Don't use attr_accessible if StrongParameters is included in the application.
This commit is contained in:
parent
6ff77290f2
commit
67acf817d2
|
@ -1,20 +1,24 @@
|
||||||
module Impressionist
|
module Impressionist
|
||||||
# Responsability
|
# Responsibility
|
||||||
# Toggles between rails > 3.1 < 4
|
# Toggles between rails > 3.1 < 4
|
||||||
# In order to make attr_accessible available in a rails app < 4
|
# In order to make attr_accessible available in a rails app < 4
|
||||||
|
|
||||||
class RailsToggle
|
class RailsToggle
|
||||||
# decides where or not to include attr_accessible
|
# decides where or not to include attr_accessible
|
||||||
def should_include?
|
def should_include?
|
||||||
ask_rails || false
|
supported_by_rails? && (not using_strong_parameters?)
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def using_strong_parameters?
|
||||||
|
defined?(StrongParameters)
|
||||||
|
end
|
||||||
|
|
||||||
# returns false if rails >= 4
|
# returns false if rails >= 4
|
||||||
# true if rails < 4
|
# true if rails < 4
|
||||||
def ask_rails
|
def supported_by_rails?
|
||||||
::Rails::VERSION::MAJOR.to_i >= 4 ? false : true
|
::Rails::VERSION::MAJOR.to_i < 4
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -15,12 +15,24 @@ module Impressionist
|
||||||
|
|
||||||
# see your_minitest_path/lib/minitest/mock.rb
|
# see your_minitest_path/lib/minitest/mock.rb
|
||||||
it "must not include attr_accessible" do
|
it "must not include attr_accessible" do
|
||||||
@toggle.stub :ask_rails, false do
|
@toggle.stub :supported_by_rails?, false do
|
||||||
refute @toggle.should_include?
|
refute @toggle.should_include?
|
||||||
end
|
end
|
||||||
end
|
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
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue