New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Automatic strong parameters detection #154
Automatic strong parameters detection #154
Conversation
…ActionController::StrongParameters module
Isn't this something that should be done via Railtie? I also wonder what happens when you have Rails first in Gemfile before hashie? |
It's possible to do the same with Railtie but I have no clue how do you test that, do you ? Not sure how order of gems will affect it |
end | ||
context 'when strong parameters are used' do | ||
before :each do | ||
module ActionController |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From a purist pov, I would try to implement this by defining, then un-defining the module. This way the test doesn't modify global state. Another, maybe better way would be to include actionpack in Gemfile with a require: false
and load that. This way the test wouldn't rely on an implementation detail.
…plementation details.
@dblock is this better? I'm starting to think the same approach could be used with rails/railtie. # gemspec
gem.add_development_dependency 'actionpack'
# mash.rb
require 'mash/railtie' if defined? ::Rails::Rightly
# mash_spec.rb
it 'does not respond to permitted?' do
expect(subject).to be_respond_to(:permitted?)
require 'rails/railtie'
load 'hashie/mash.rb'
expect( subject ).not_to be_respond_to(:permitted?)
expect { subject.method(:permitted?) }.to raise_error(NameError)
expect { subject.permitted? }.to raise_error(ArgumentError)
end Thoughts? |
Ah just realised the whole module doesn't actually work due to the way modules got included in ruby :\
So based on the example in your tests you have used the sneaky method and that's why the test passed. However, if you actually try to include the module into Mash in an initialiser it's not gonna work. |
Lets ignore the test for a second. Isn't Railtie the "official" way of doing this? require 'rails'
class Hashie::Extensions::Mash::ActiveModel::Railtie < Rails::Railtie
initializer "mash" do
Mash.send :include, Hashie::Extensions::Mash::ActiveModel
end
end Or something like that? Or are you saying it's not going to work either way for the reason above (order of includes)? In which case we should just use It would be very helpful to get a quick Rails project together that has a spec that we can test against HEAD of Hashie. |
@dblock I have tried alias method before and it works. It would be a good idea to have a dummy app. But it's hard to combine them together inside this gem. What are you thoughts on moving this logic from hashie to hashie-rails ? |
I would be down with hashie-rails. |
@dblock Apologise for delay. RL got in the way : |
Looks great. Can you please PR a README change to Hashie that talks about Hashie+Rails integration via HashieRails? There's also things to change in UPGRADING and possibly CHANGELOG. A README on the HashieRails side will also be useful. We can close this issue then and I will cut a 3.0 release. Thx. |
See #162 |
Committed 41e6c67 for README. @Maxim-Filimonov Should we get rid of Hashie::Mash::ActiveModel? |
Just did see -> #163 |
Should prevent users from creating an extra initializer when used in Rails 4 or with StrongParameters gem