Skip to content

Commit

Permalink
Update README for new test helper.
Browse files Browse the repository at this point in the history
  • Loading branch information
Erich Menge committed Apr 30, 2013
1 parent 8991182 commit a49e943
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion README.md
Expand Up @@ -143,12 +143,40 @@ SignedForm.config do |c|
c.digest_store = SignedForm::DigestStores::NullStore.new
c.secret_key = 'supersecret'
end

```

Those options that are in the options hash are the default per-form options. They can be overridden by passing the same
option to the `signed_form_for` method.

## Testing Your Controllers

Because your tests won't include a signature you will get a `ForbiddenAttributes` exception in your tests that do mass
assignment. SignedForm includes a helper that works with both TestUnit and RSpec to help.

Since you're using SignedForm there is no need test attribute assignment so you may as well permit all attributes. Which
is the name of the helper SignedForm provides. In your `spec_helper` file or `test_helper` file `require
'signed_form/test_helper'`. Once you do this `permit_all_attributes` is available in your tests/specs.

**Caution** `permit_all_attributes` modifies the class of the controller instance under test for the duration of the
test. If you want to restore the class mid-test `permit_all_attributes` takes an optional block. Example:

```ruby
describe "POST create" do
describe "with valid params" do
it "assigns a newly created car as @car" do
permit_all_parameters do
post :create, {:car => valid_attributes}, valid_session
assigns(:car).should be_a(Car)
assigns(:car).should be_persisted
end
assigns(:car).should be_nil # This is nil because it was never set on the original controller
end
end
end
```

But this block shouldn't normally be needed. Again the controller class is only affected for the current test.

## I want to hear from you

If you're using SignedForm, I'd love to hear from you. What do you like? What could be better? I'd love to hear your
Expand Down

0 comments on commit a49e943

Please sign in to comment.