activeadmin / inherited_resources

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

rails generate scaffold creates failing tests with IR in rails 4

davidmiani opened this issue · comments

Steps to reproduce:

# make sure rails 4 is active
rvm use 2.0.0@rails4

rails new testsite
cd testsite

# skipping the below line will result in the tests passing
echo "gem 'inherited_resources', :git => 'https://github.com/josevalim/inherited_resources'" >> Gemfile

bundle install
rails generate scaffold Product title:string price:decimal
rake db:migrate
rake test

Resulting errors:

# Running tests:

E..DEPRECATION WARNING: Model.scoped is deprecated. Please use Model.all instead. (called from block in <class:ProductsControllerTest> at /Volumes/Home/Documents/programming/ruby/rails/rails_templates/test/testsite/test/controllers/products_controller_test.rb:9)
...E

Finished tests in 0.818742s, 8.5497 tests/s, 9.7711 assertions/s.

  1) Error:
ProductsControllerTest#test_should_create_product:
ActiveModel::ForbiddenAttributesError: ActiveModel::ForbiddenAttributesError
    test/controllers/products_controller_test.rb:21:in `block (2 levels) in <class:ProductsControllerTest>'
    test/controllers/products_controller_test.rb:20:in `block in <class:ProductsControllerTest>'

  2) Error:
ProductsControllerTest#test_should_update_product:
ActiveModel::ForbiddenAttributesError: ActiveModel::ForbiddenAttributesError
    test/controllers/products_controller_test.rb:38:in `block in <class:ProductsControllerTest>'

7 tests, 8 assertions, 0 failures, 2 errors, 0 skips

The solution is simple - just adding the below to the products_controller.rb file:

    def build_resource_params
        [params.fetch(:product, {}).permit(:title, :price)]
    end

It would be much better though if the generator did this (or something similar) by itself.

Sorry, don't know to to link pull request to issue.
Here is mine #378