diff --git a/README.md b/README.md index 198dac2..21ffd0b 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/app/controllers/impressionist_controller.rb b/app/controllers/impressionist_controller.rb index b92fcbf..f23a9fc 100644 --- a/app/controllers/impressionist_controller.rb +++ b/app/controllers/impressionist_controller.rb @@ -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) diff --git a/tests/test_app/app/controllers/application_controller.rb b/tests/test_app/app/controllers/application_controller.rb index 1ce61fa..077d62d 100644 --- a/tests/test_app/app/controllers/application_controller.rb +++ b/tests/test_app/app/controllers/application_controller.rb @@ -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 diff --git a/tests/test_app/app/controllers/articles_controller.rb b/tests/test_app/app/controllers/articles_controller.rb index 367b460..559c9e0 100644 --- a/tests/test_app/app/controllers/articles_controller.rb +++ b/tests/test_app/app/controllers/articles_controller.rb @@ -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] diff --git a/tests/test_app/config/environments/development.rb b/tests/test_app/config/environments/development.rb index b5306b3..c69665e 100644 --- a/tests/test_app/config/environments/development.rb +++ b/tests/test_app/config/environments/development.rb @@ -23,7 +23,7 @@ TestApp::Application.configure do config.action_dispatch.best_standards_support = :builtin # Raise exception on mass assignment protection for Active Record models - config.active_record.mass_assignment_sanitizer = :strict + # config.active_record.mass_assignment_sanitizer = :strict # Log the query plan for queries taking more than this (works # with SQLite, MySQL, and PostgreSQL) diff --git a/tests/test_app/config/environments/test.rb b/tests/test_app/config/environments/test.rb index 21ec8e4..6eb922c 100644 --- a/tests/test_app/config/environments/test.rb +++ b/tests/test_app/config/environments/test.rb @@ -30,7 +30,7 @@ TestApp::Application.configure do config.action_mailer.delivery_method = :test # Raise exception on mass assignment protection for Active Record models - config.active_record.mass_assignment_sanitizer = :strict + # config.active_record.mass_assignment_sanitizer = :strict # Print deprecation notices to the stderr config.active_support.deprecation = :stderr diff --git a/tests/test_app/spec/controllers/articles_controller_spec.rb b/tests/test_app/spec/controllers/articles_controller_spec.rb index 15454cd..ab35124 100644 --- a/tests/test_app/spec/controllers/articles_controller_spec.rb +++ b/tests/test_app/spec/controllers/articles_controller_spec.rb @@ -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 - - diff --git a/tests/test_app/spec/initializers/initializers_spec.rb b/tests/test_app/spec/initializers/initializers_spec.rb index 398f49b..44d06ca 100644 --- a/tests/test_app/spec/initializers/initializers_spec.rb +++ b/tests/test_app/spec/initializers/initializers_spec.rb @@ -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