Skip to content

Commit

Permalink
Merge branch 'master' into gh-308-warn-redefine
Browse files Browse the repository at this point in the history
  • Loading branch information
tfausak committed Oct 16, 2015
2 parents dd2f43f + f38127f commit c9eed45
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 9 deletions.
2 changes: 0 additions & 2 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,3 @@ PercentLiteralDelimiters:
'%W': '[]'
'%i': '[]'
'%w': '[]'
TrivialAccessors:
ExactNameMatch: true
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

- [#310][]: Added a warning when a filter is redefined.

## Changed

- [#311][]: Changed the error message when defining the default value for a
hash.

# [2.1.3][] (2015-10-02)

## Fixed
Expand Down
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ BooleanInteraction.run!(kool_aid: true)

### File

File filters also accept `TempFile`s and anything that responds to `#tempfile`.
File filters also accept `TempFile`s and anything that responds to `#rewind`.
That means that you can pass the `params` from uploading files via forms in
Rails.

Expand Down Expand Up @@ -614,7 +614,8 @@ IntegerInteraction.run!(limit: 10)
ActiveInteraction plays nicely with Rails. You can use interactions to handle
your business logic instead of models or controllers. To see how it all works,
let's take a look at a complete example of a controller with the typical
resourceful actions.
resourceful actions. For a complete working example, check out [Aire][], our
example Rails application.

### Controller

Expand Down Expand Up @@ -1167,7 +1168,7 @@ input type.
### Optional inputs

Optional inputs can be defined by using the `:default` option as described in
[the Filters section][]. Within the interaction, provided and default values
[the filters section][]. Within the interaction, provided and default values
are merged to create `inputs`. There are times where it is useful to know
whether a value was passed to `run` or the result of a filter default. In
particular, it is useful when `nil` is an acceptable value. For example, you
Expand All @@ -1194,10 +1195,13 @@ And if you want to update it, pass in the new value as usual.

``` rb
user = User.find(...)

# Don't update their birthday.
UpdateUser.run!(user: user)

# Remove their birthday.
UpdateUser.run!(user: user, birthday: nil)

# Update their birthday.
UpdateUser.run!(user: user, birthday: Date.new(2000, 1, 2))
```
Expand Down Expand Up @@ -1288,8 +1292,6 @@ available on GitHub.

ActiveInteraction is licensed under [the MIT License][].

Logo design by [Tyler Lee][].

[the project page]: http://orgsync.github.io/active_interaction/
[the full documentation]: http://rubydoc.info/github/orgsync/active_interaction
[semantic versioning]: http://semver.org/spec/v2.0.0.html
Expand All @@ -1307,4 +1309,4 @@ Logo design by [Tyler Lee][].
[formtastic]: https://rubygems.org/gems/formtastic
[simple_form]: https://rubygems.org/gems/simple_form
[the filters section]: #filters
[tyler lee]: https://github.com/tylerlee
[aire]: example
2 changes: 2 additions & 0 deletions lib/active_interaction/filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ def default
fail InvalidValueError if value.is_a?(GroupedInput)

cast(value)
rescue InvalidNestedValueError => error
raise InvalidDefaultError, "#{name}: #{value.inspect} (#{error})"
rescue InvalidValueError, MissingValueError
raise InvalidDefaultError, "#{name}: #{value.inspect}"
end
Expand Down
12 changes: 11 additions & 1 deletion spec/active_interaction/integration/hash_interaction_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
end

context 'with an invalid nested default' do
it 'raises an error' do
it 'raises an error with a non-empty hash' do
expect do
Class.new(ActiveInteraction::Base) do
hash :a, default: { x: Object.new } do
Expand All @@ -64,5 +64,15 @@
end
end.to raise_error ActiveInteraction::InvalidDefaultError
end

it 'raises an error' do
expect do
Class.new(ActiveInteraction::Base) do
hash :a, default: {} do
hash :x
end
end
end.to raise_error ActiveInteraction::InvalidDefaultError
end
end
end

0 comments on commit c9eed45

Please sign in to comment.