From 67acf817d281243f330a27a30e1207ff375abccf Mon Sep 17 00:00:00 2001 From: "Peter M. Goldstein" Date: Sun, 22 Sep 2013 10:54:25 -0700 Subject: [PATCH] Don't use attr_accessible if StrongParameters is included in the application. --- lib/impressionist/rails_toggle.rb | 12 ++++++++---- tests/spec/rails_toggle_spec.rb | 14 +++++++++++++- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/lib/impressionist/rails_toggle.rb b/lib/impressionist/rails_toggle.rb index 5dbe06c..19d3566 100644 --- a/lib/impressionist/rails_toggle.rb +++ b/lib/impressionist/rails_toggle.rb @@ -1,20 +1,24 @@ module Impressionist - # Responsability + # Responsibility # Toggles between rails > 3.1 < 4 # In order to make attr_accessible available in a rails app < 4 class RailsToggle # decides where or not to include attr_accessible def should_include? - ask_rails || false + supported_by_rails? && (not using_strong_parameters?) end private + def using_strong_parameters? + defined?(StrongParameters) + end + # returns false if rails >= 4 # true if rails < 4 - def ask_rails - ::Rails::VERSION::MAJOR.to_i >= 4 ? false : true + def supported_by_rails? + ::Rails::VERSION::MAJOR.to_i < 4 end end diff --git a/tests/spec/rails_toggle_spec.rb b/tests/spec/rails_toggle_spec.rb index b74c76a..27243d6 100644 --- a/tests/spec/rails_toggle_spec.rb +++ b/tests/spec/rails_toggle_spec.rb @@ -15,12 +15,24 @@ module Impressionist # see your_minitest_path/lib/minitest/mock.rb it "must not include attr_accessible" do - @toggle.stub :ask_rails, false do + @toggle.stub :supported_by_rails?, false do refute @toggle.should_include? end end end + describe "Strong Parameters" do + + # see your_minitest_path/lib/minitest/mock.rb + it "must not include attr_accessible" do + @toggle.stub :supported_by_rails?, true do + @toggle.stub :using_strong_parameters?, true do + refute @toggle.should_include? + end + end + end + + end end end