Merge pull request #241 from msimonborg/patch-1
before_filter -> before_action
This commit is contained in:
commit
529f9d494d
|
@ -139,7 +139,7 @@ Usage
|
|||
@widget.impressionist_count(:message=>"pageview", :filter=>:all)
|
||||
|
||||
Logging impressions for authenticated users happens automatically. If you have
|
||||
a current_user helper or use @current_user in your before_filter to set your
|
||||
a current_user helper or use @current_user in your before_filter (or before_action in Rails >= 5.0) to set your
|
||||
authenticated user, current_user.id will be written to the user_id field in the
|
||||
impressions table.
|
||||
|
||||
|
|
|
@ -3,13 +3,21 @@ require 'digest/sha2'
|
|||
module ImpressionistController
|
||||
module ClassMethods
|
||||
def impressionist(opts={})
|
||||
before_filter { |c| c.impressionist_subapp_filter(opts) }
|
||||
if Rails::VERSION::MAJOR >= 5
|
||||
before_action { |c| c.impressionist_subapp_filter(opts) }
|
||||
else
|
||||
before_filter { |c| c.impressionist_subapp_filter(opts) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
module InstanceMethods
|
||||
def self.included(base)
|
||||
base.before_filter :impressionist_app_filter
|
||||
if Rails::VERSION::MAJOR >= 5
|
||||
base.before_action :impressionist_app_filter
|
||||
else
|
||||
base.before_filter :impressionist_app_filter
|
||||
end
|
||||
end
|
||||
|
||||
def impressionist(obj,message=nil,opts={})
|
||||
|
@ -103,7 +111,7 @@ module ImpressionistController
|
|||
request_param = params_hash
|
||||
impressions.detect{|impression| impression.params == request_param }.nil?
|
||||
end
|
||||
|
||||
|
||||
# creates the query to check for uniqueness
|
||||
def unique_query(unique_opts,impressionable=nil)
|
||||
full_statement = direct_create_statement({},impressionable)
|
||||
|
|
|
@ -1,8 +1,12 @@
|
|||
class ApplicationController < ActionController::Base
|
||||
protect_from_forgery
|
||||
before_filter :secondary_before_filter
|
||||
if Rails::VERSION::MAJOR >= 5
|
||||
before_action :secondary_before_action
|
||||
else
|
||||
before_filter :secondary_before_action
|
||||
end
|
||||
|
||||
def secondary_before_filter
|
||||
@test_secondary_before_filter = "this is a test"
|
||||
def secondary_before_action
|
||||
@test_secondary_before_action = "this is a test"
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
class ArticlesController < ApplicationController
|
||||
before_filter :test_current_user_var
|
||||
if Rails::VERSION::MAJOR >= 5
|
||||
before_action :test_current_user_var
|
||||
else
|
||||
before_filter :test_current_user_var
|
||||
end
|
||||
|
||||
def test_current_user_var
|
||||
if session[:user_id]
|
||||
|
|
|
@ -26,7 +26,7 @@ describe ArticlesController do
|
|||
Article.first.impressions.last.action_name.should eq "show"
|
||||
end
|
||||
|
||||
it "should log the user_id if user is authenticated (@current_user before_filter method)" do
|
||||
it "should log the user_id if user is authenticated (@current_user before_action method)" do
|
||||
session[:user_id] = 123
|
||||
get "show", :id=> 1
|
||||
Article.first.impressions.last.user_id.should eq 123
|
||||
|
@ -72,5 +72,3 @@ describe ArticlesController do
|
|||
Impression.last.referrer.should eq nil
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ describe Impressionist do
|
|||
expect(ApplicationController).to respond_to(method)
|
||||
end
|
||||
|
||||
it "should include the before_filter method in ApplicationController" do
|
||||
it "should include the before_action method in ApplicationController" do
|
||||
filters = ApplicationController._process_action_callbacks.select { |c| c.kind == :before }
|
||||
filters.collect{|filter|filter.filter}.include?(:impressionist_app_filter).should be_true
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue