On Thursday, August 4, 2011 1:35:15 PM UTC-6, Walter Lee Davis wrote: > > I am doing controller testing, and I can't seem to get the create > method test to pass when friendly_id is added to the mix. If I comment > it out of the model, the tests all pass perfectly. The moment I add it > back in, the error looks like this: > > 1) Error: > test_create_valid(BrandsControllerTest): > FriendlyId::BlankError: FriendlyId::BlankError > app/controllers/brands_controller.rb:16:in `create' > test/functional/brands_controller_test.rb:27:in `test_create_valid' > > Here's the relevant line in brand.rb: > > has_friendly_id :name, :use_slug => true, :approximate_ascii => true > > Here's the test (using mocha): > > def test_create_valid > Brand.any_instance.stubs(:valid?).returns(true) > post :create > assert_redirected_to brand_url(assigns(:brand)) > end >
I'm gonna take a stab at this and say it's because you're not posting a name parameter to the create action. Therefor, the create action is trying to create a new Brand w/out a name. Since you're using the friendly_id gem and configuring the Brand model to use its "name" field as the friendly id, you must provide a name else you get FriendlyId::BlankError. > Here's the fixture: > > one: > name: MyString > image_file_name: MyString > image_content_type: MyString > image_file_size: 1 > image_updated_at: 2011-08-03 10:49:03 > tease: MyText > description: MyText > Doesn't really matter what you have in your fixtures since you're simulating a request that results in a call to your #create action in your controller which will create a new (blank) Brand record. > All other tests pass, and if I comment out has_friendly_id, the create > tests pass as well. Does this ring any bells for anyone? > > Thanks in advance, > > Walter > -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/vVodkyMZiGIJ. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

