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

active_scaffold_controller_generator generates failing tests #112

Open
aspiers opened this Issue Jan 8, 2012 · 7 comments

Comments

Projects
None yet
2 participants
@aspiers
Copy link

aspiers commented Jan 8, 2012

If I understand it right, AS piggy-backs onto the standard generators for generating functional tests for a new controller. However, as noted in this post, an AS handler for the #create action expects the new record's attributes to be passed via params[:record], not params[model.to_s]. That means a controller test freshly generated by active_scaffold_controller_generator will fail until that param key is tweaked to be :record.

@jagipson

This comment has been minimized.

Copy link

jagipson commented Jan 9, 2012

I also have this problem. Is there a fix or workaround, besides emptying the functional test file ?

@aspiers

This comment has been minimized.

Copy link

aspiers commented Jan 9, 2012

Yes, like I said above, change the params key to :record:

      post :create, { :commit => "Create", :record => new_record }

Works fine.

@jagipson

This comment has been minimized.

Copy link

jagipson commented Jan 9, 2012

Still having problems. Steps to reproduce:

rails new as_test && cd as_test

edit Gemfile, add:

gem 'active_scaffold'

then run

bundle install
rails g active_scaffold article author:string body:text

edit test/functional/articles_controller_test.rb:
change:

test "should create article" do
    assert_difference('Article.count') do
      post :create, article: @article.attributes
    end
    assert_redirected_to article_path(assigns(:article))
end 

To:

test "should create article" do
  assert_difference('Article.count') do
    post :create, {:commit => 'create', :record => {:author => 'john doe',
                                                    :post   => 'test' }
                  }
  end

  assert_redirected_to article_path(assigns(:article))
end
@aspiers

This comment has been minimized.

Copy link

aspiers commented Jan 9, 2012

Please describe the problems you are having.

@jagipson

This comment has been minimized.

Copy link

jagipson commented Jan 9, 2012

The test now throws:

 test_should_create_article                                          ERROR
    No route matches {:action=>"show", :controller=>"articles"}
    STDERR:
    Exception `ActionController::RoutingError' at /home/jagipson/.rvm/gems/ruby-1.9.3-p0/gems/actionpack-3.1.3/lib/action_dispatch/routing/route_set.rb:465:in `raise_routing_error'
    /home/jagipson/.rvm/gems/ruby-1.9.3-p0/gems/actionpack-3.1.3/lib/action_dispatch/routing/route_set.rb:455:in `generate'
    /home/jagipson/.rvm/gems/ruby-1.9.3-p0/gems/actionpack-3.1.3/lib/action_dispatch/routing/route_set.rb:494:in `generate'
    /home/jagipson/.rvm/gems/ruby-1.9.3-p0/gems/active_scaffold-3.1.13/lib/active_scaffold/extensions/nil_id_in_url_params.rb:4:in `generate_with_nil_id_awareness'
    /home/jagipson/.rvm/gems/ruby-1.9.3-p0/gems/actionpack-3.1.3/lib/action_dispatch/routing/route_set.rb:519:in `url_for'
    /home/jagipson/.rvm/gems/ruby-1.9.3-p0/gems/actionpack-3.1.3/lib/action_dispatch/routing/url_for.rb:147:in `url_for'
    /home/jagipson/.rvm/gems/ruby-1.9.3-p0/gems/actionpack-3.1.3/lib/action_dispatch/routing/route_set.rb:201:in `article_path'
    /home/jagipson/.rvm/gems/ruby-1.9.3-p0/gems/actionpack-3.1.3/lib/action_dispatch/testing/assertions/routing.rb:173:in `method_missing'
    test/functional/articles_controller_test.rb:27:in `block in <class:ArticlesControllerTest>'
    /home/jagipson/.rvm/gems/ruby-1.9.3-p0/gems/activesupport-3.1.3/lib/active_support/testing/setup_and_teardown.rb:35:in `block in run'
    /home/jagipson/.rvm/gems/ruby-1.9.3-p0/gems/activesupport-3.1.3/lib/active_support/callbacks.rb:444:in `_run_setup_callbacks'
    /home/jagipson/.rvm/gems/ruby-1.9.3-p0/gems/activesupport-3.1.3/lib/active_support/callbacks.rb:81:in `run_callbacks'
    /home/jagipson/.rvm/gems/ruby-1.9.3-p0/gems/activesupport-3.1.3/lib/active_support/testing/setup_and_teardown.rb:34:in `run'
@jagipson

This comment has been minimized.

Copy link

jagipson commented Jan 9, 2012

I should add that the config/routes.rb generated is correct:

AsTest::Application.routes.draw do
  resources :articles do as_routes end
end
@jagipson

This comment has been minimized.

Copy link

jagipson commented Jan 9, 2012

Okay. The problem was in my confusion about how AS operates. After adding an entry it does not redirect to the "Show" page for an item, but rather back to the index page.

Changing:

assert_redirected_to article_path(assigns(:article))

To:

    assert_redirected_to articles_path

Does the trick.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment