Skip to content
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

Updates specs and code to use Rails 5 methods and params patterns #8

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
260 changes: 132 additions & 128 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,175 +1,179 @@
PATH
remote: .
specs:
params_deserializers (1.2.0)
activesupport (>= 3.2.16, < 5.0)
params_deserializers (2.0.0)
activesupport (>= 5.0)

GEM
remote: https://rubygems.org/
specs:
actionmailer (4.2.1)
actionpack (= 4.2.1)
actionview (= 4.2.1)
activejob (= 4.2.1)
actioncable (5.1.4)
actionpack (= 5.1.4)
nio4r (~> 2.0)
websocket-driver (~> 0.6.1)
actionmailer (5.1.4)
actionpack (= 5.1.4)
actionview (= 5.1.4)
activejob (= 5.1.4)
mail (~> 2.5, >= 2.5.4)
rails-dom-testing (~> 1.0, >= 1.0.5)
actionpack (4.2.1)
actionview (= 4.2.1)
activesupport (= 4.2.1)
rack (~> 1.6)
rack-test (~> 0.6.2)
rails-dom-testing (~> 1.0, >= 1.0.5)
rails-html-sanitizer (~> 1.0, >= 1.0.1)
actionview (4.2.1)
activesupport (= 4.2.1)
rails-dom-testing (~> 2.0)
actionpack (5.1.4)
actionview (= 5.1.4)
activesupport (= 5.1.4)
rack (~> 2.0)
rack-test (>= 0.6.3)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.0.2)
actionview (5.1.4)
activesupport (= 5.1.4)
builder (~> 3.1)
erubis (~> 2.7.0)
rails-dom-testing (~> 1.0, >= 1.0.5)
rails-html-sanitizer (~> 1.0, >= 1.0.1)
activejob (4.2.1)
activesupport (= 4.2.1)
globalid (>= 0.3.0)
activemodel (4.2.1)
activesupport (= 4.2.1)
builder (~> 3.1)
activerecord (4.2.1)
activemodel (= 4.2.1)
activesupport (= 4.2.1)
arel (~> 6.0)
activesupport (4.2.1)
erubi (~> 1.4)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.0.3)
activejob (5.1.4)
activesupport (= 5.1.4)
globalid (>= 0.3.6)
activemodel (5.1.4)
activesupport (= 5.1.4)
activerecord (5.1.4)
activemodel (= 5.1.4)
activesupport (= 5.1.4)
arel (~> 8.0)
activesupport (5.1.4)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (~> 0.7)
json (~> 1.7, >= 1.7.7)
minitest (~> 5.1)
thread_safe (~> 0.3, >= 0.3.4)
tzinfo (~> 1.1)
arel (6.0.0)
builder (3.2.2)
celluloid (0.16.0)
timers (~> 4.0.0)
coderay (1.1.0)
diff-lcs (1.2.5)
erubis (2.7.0)
ffi (1.9.8)
arel (8.0.0)
builder (3.2.3)
coderay (1.1.2)
concurrent-ruby (1.0.5)
crass (1.0.2)
diff-lcs (1.3)
erubi (1.6.1)
ffi (1.9.18)
formatador (0.2.5)
globalid (0.3.5)
activesupport (>= 4.1.0)
guard (2.12.5)
globalid (0.4.0)
activesupport (>= 4.2.0)
guard (2.14.1)
formatador (>= 0.2.4)
listen (~> 2.7)
listen (>= 2.7, < 4.0)
lumberjack (~> 1.0)
nenv (~> 0.1)
notiffany (~> 0.0)
pry (>= 0.9.12)
shellany (~> 0.0)
thor (>= 0.18.1)
guard-compat (1.2.1)
guard-rspec (4.5.0)
guard-rspec (4.7.3)
guard (~> 2.1)
guard-compat (~> 1.1)
rspec (>= 2.99.0, < 4.0)
hitimes (1.2.2)
i18n (0.7.0)
json (1.8.2)
listen (2.10.0)
celluloid (~> 0.16.0)
rb-fsevent (>= 0.9.3)
rb-inotify (>= 0.9)
loofah (2.0.2)
i18n (0.8.6)
listen (3.1.5)
rb-fsevent (~> 0.9, >= 0.9.4)
rb-inotify (~> 0.9, >= 0.9.7)
ruby_dep (~> 1.2)
loofah (2.1.1)
crass (~> 1.0.2)
nokogiri (>= 1.5.9)
lumberjack (1.0.9)
mail (2.6.3)
mime-types (>= 1.16, < 3)
method_source (0.8.2)
mime-types (2.5)
mini_portile (0.6.2)
minitest (5.6.1)
nenv (0.2.0)
nokogiri (1.6.6.2)
mini_portile (~> 0.6.0)
notiffany (0.0.6)
lumberjack (1.0.12)
mail (2.6.6)
mime-types (>= 1.16, < 4)
method_source (0.9.0)
mime-types (3.1)
mime-types-data (~> 3.2015)
mime-types-data (3.2016.0521)
mini_portile2 (2.3.0)
minitest (5.10.3)
nenv (0.3.0)
nio4r (2.1.0)
nokogiri (1.8.1)
mini_portile2 (~> 2.3.0)
notiffany (0.1.1)
nenv (~> 0.1)
shellany (~> 0.0)
pry (0.10.1)
pry (0.11.1)
coderay (~> 1.1.0)
method_source (~> 0.8.1)
slop (~> 3.4)
rack (1.6.1)
rack-test (0.6.3)
rack (>= 1.0)
rails (4.2.1)
actionmailer (= 4.2.1)
actionpack (= 4.2.1)
actionview (= 4.2.1)
activejob (= 4.2.1)
activemodel (= 4.2.1)
activerecord (= 4.2.1)
activesupport (= 4.2.1)
bundler (>= 1.3.0, < 2.0)
railties (= 4.2.1)
sprockets-rails
rails-deprecated_sanitizer (1.0.3)
activesupport (>= 4.2.0.alpha)
rails-dom-testing (1.0.6)
activesupport (>= 4.2.0.beta, < 5.0)
nokogiri (~> 1.6.0)
rails-deprecated_sanitizer (>= 1.0.1)
rails-html-sanitizer (1.0.2)
method_source (~> 0.9.0)
rack (2.0.3)
rack-test (0.7.0)
rack (>= 1.0, < 3)
rails (5.1.4)
actioncable (= 5.1.4)
actionmailer (= 5.1.4)
actionpack (= 5.1.4)
actionview (= 5.1.4)
activejob (= 5.1.4)
activemodel (= 5.1.4)
activerecord (= 5.1.4)
activesupport (= 5.1.4)
bundler (>= 1.3.0)
railties (= 5.1.4)
sprockets-rails (>= 2.0.0)
rails-dom-testing (2.0.3)
activesupport (>= 4.2.0)
nokogiri (>= 1.6)
rails-html-sanitizer (1.0.3)
loofah (~> 2.0)
railties (4.2.1)
actionpack (= 4.2.1)
activesupport (= 4.2.1)
railties (5.1.4)
actionpack (= 5.1.4)
activesupport (= 5.1.4)
method_source
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)
rake (10.4.2)
rb-fsevent (0.9.4)
rb-inotify (0.9.5)
ffi (>= 0.5.0)
rspec (3.2.0)
rspec-core (~> 3.2.0)
rspec-expectations (~> 3.2.0)
rspec-mocks (~> 3.2.0)
rspec-core (3.2.3)
rspec-support (~> 3.2.0)
rspec-expectations (3.2.1)
rake (12.1.0)
rb-fsevent (0.10.2)
rb-inotify (0.9.10)
ffi (>= 0.5.0, < 2)
rspec (3.6.0)
rspec-core (~> 3.6.0)
rspec-expectations (~> 3.6.0)
rspec-mocks (~> 3.6.0)
rspec-core (3.6.0)
rspec-support (~> 3.6.0)
rspec-expectations (3.6.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.2.0)
rspec-mocks (3.2.1)
rspec-support (~> 3.6.0)
rspec-mocks (3.6.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.2.0)
rspec-rails (3.2.1)
actionpack (>= 3.0, < 4.3)
activesupport (>= 3.0, < 4.3)
railties (>= 3.0, < 4.3)
rspec-core (~> 3.2.0)
rspec-expectations (~> 3.2.0)
rspec-mocks (~> 3.2.0)
rspec-support (~> 3.2.0)
rspec-support (3.2.2)
shellany (0.0.1)
slop (3.6.0)
sprockets (3.0.3)
rack (~> 1.0)
sprockets-rails (2.2.4)
rspec-support (~> 3.6.0)
rspec-rails (3.6.1)
actionpack (>= 3.0)
activesupport (>= 3.0)
sprockets (>= 2.8, < 4.0)
sqlite3 (1.3.10)
thor (0.19.1)
thread_safe (0.3.5)
timers (4.0.1)
hitimes
tzinfo (1.2.2)
railties (>= 3.0)
rspec-core (~> 3.6.0)
rspec-expectations (~> 3.6.0)
rspec-mocks (~> 3.6.0)
rspec-support (~> 3.6.0)
rspec-support (3.6.0)
ruby_dep (1.5.0)
shellany (0.0.1)
sprockets (3.7.1)
concurrent-ruby (~> 1.0)
rack (> 1, < 3)
sprockets-rails (3.2.1)
actionpack (>= 4.0)
activesupport (>= 4.0)
sprockets (>= 3.0.0)
sqlite3 (1.3.13)
thor (0.20.0)
thread_safe (0.3.6)
tzinfo (1.2.3)
thread_safe (~> 0.1)
websocket-driver (0.6.5)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.2)

PLATFORMS
ruby

DEPENDENCIES
guard-rspec
params_deserializers!
rails (>= 4.2)
rails (>= 5.0)
rspec-rails
sqlite3

BUNDLED WITH
1.10.6
1.16.0.pre.2
2 changes: 1 addition & 1 deletion lib/params_deserializers/deserialize_params_with.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def deserialize_params_with(deserializer, options = {})
deserialized_params_name = options.delete(:as).try(:to_sym) || :deserialized_params
attr_reader deserialized_params_name

before_filter(options) do
before_action(options) do
instance_variable_set("@#{deserialized_params_name}", deserializer.new(params).deserialize)
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/params_deserializers/params_deserializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def verify_root_key_exists
end

def verify_valid_keys
invalid_params = params_root.symbolize_keys.keys - self.class.attrs.map(&:original_name)
invalid_params = params.permit(params_root.keys).to_h.symbolize_keys.keys - self.class.attrs.map(&:original_name)
if self.class.strict_mode && !invalid_params.empty?
raise InvalidKeyError, "Invalid keys in params: #{invalid_params.map(&:inspect).join(",")}."
end
Expand Down
2 changes: 1 addition & 1 deletion lib/params_deserializers/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@
# POSSIBILITY OF SUCH DAMAGE.

module ParamsDeserializers
VERSION = "1.2.0"
VERSION = "2.0.0"
end
4 changes: 2 additions & 2 deletions params_deserializers.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ Gem::Specification.new do |s|

s.files = Dir['lib/**/*', 'Rakefile', 'README.md']

s.add_dependency 'activesupport', '>= 3.2.16', '< 5.0'
s.add_dependency 'activesupport', '>= 5.0'

s.add_development_dependency 'guard-rspec'
s.add_development_dependency 'sqlite3'
s.add_development_dependency 'rails', '>= 4.2'
s.add_development_dependency 'rails', '>= 5.0'
s.add_development_dependency 'rspec-rails'
end
3 changes: 0 additions & 3 deletions spec/dummy/config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ class Application < Rails::Application
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
# config.i18n.default_locale = :de

# Do not swallow errors in after_commit/after_rollback callbacks.
config.active_record.raise_in_transactional_callbacks = true
end
end

7 changes: 3 additions & 4 deletions spec/params_deserializers/deserialize_params_with_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,10 @@
deserializer = Class.new(ParamsDeserializer) do
attributes :foo
end

deserialize_params_with deserializer, only: :update

def update
render text: ''
render plain: ''
end
end

Expand All @@ -54,7 +53,7 @@ def update

it 'gets deserialized params when calling the deserialized_params getter' do
routes.draw { get 'update' => 'anonymous#update' }
put :update, foo: 'bar', baz: 'quux'
put :update, params: { foo: 'bar', baz: 'quux' }

expected = { foo: 'bar' }.with_indifferent_access
expect(controller.deserialized_params).to eql expected
Expand All @@ -72,7 +71,7 @@ def update
deserialize_params_with deserializer, as: :deserialized_params_foo, only: :update

def update
render text: ''
render plain: ''
end
end

Expand Down
Loading