I understand that in order to functional test a nested resource, you need to pass the id of the parent resource. I am having a problem testing the ''edit'' action on the nested resource. Here is the failing test. test "should get edit" do get :edit, id: capability_types(:one).id, capability_category_id: capability_categories(:one).id assert_response :success end id: capability_types(:one).id is passing the id from the capability_types fixture. I am setting the capability_category_id from the capability_categories fixture. I am getting this error message. Couldn''t find CapabilityType with id=980190962 [WHERE "capability_types"."capability_category_id" = $1] Exception `ActiveRecord::RecordNotFound'' #fixtures capability_types.yml one: name: MyString capability_category_id: 1 two: name: MyString capability_category_id: 1 capability_categories.yml one: name: MyString two: name: MyString ''edit'' action in the controller def edit @capability_type = @capability_category.capability_types.find(params[:id]) end I am using Rails 4 and have a before_action defined to set_the capability_category. before_action :set_capability_category def set_capability_category @capability_category = CapabilityCategory.find(params[:capability_category_id]) end *I can see anything that I''ve done that should not work. Any ideas? would be greatly appreciated.* -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/u7iYyI6UqgYJ. For more options, visit https://groups.google.com/groups/opt_out.
I managed to get this to work. I used the fixture name instead of the rigid foreign key id in the capability_test.yml fixture. Thus, #fixtures capability_types.yml one: name: MyString capability_category: one two: name: MyString capability_category: one On Monday, February 4, 2013 9:03:40 AM UTC-6, AmateurCoder wrote:> > I understand that in order to functional test a nested resource, you need > to pass the id of the parent resource. I am having a problem testing the > ''edit'' action on the nested resource. > > Here is the failing test. > > test "should get edit" do > get :edit, id: capability_types(:one).id, capability_category_id: > capability_categories(:one).id > assert_response :success > end > > id: capability_types(:one).id is passing the id from the capability_types > fixture. I am setting the capability_category_id from the > capability_categories fixture. > > I am getting this error message. > > Couldn''t find CapabilityType with id=980190962 [WHERE > "capability_types"."capability_category_id" = $1] > Exception `ActiveRecord::RecordNotFound'' > > #fixtures > capability_types.yml > one: > name: MyString > capability_category_id: 1 > > two: > name: MyString > capability_category_id: 1 > > capability_categories.yml > one: > name: MyString > > two: > name: MyString > > ''edit'' action in the controller > def edit > @capability_type = > @capability_category.capability_types.find(params[:id]) > end > > I am using Rails 4 and have a before_action defined to set_the > capability_category. > > before_action :set_capability_category > > def set_capability_category > @capability_category = > CapabilityCategory.find(params[:capability_category_id]) > end > > *I can see anything that I''ve done that should not work. Any ideas? > would be greatly appreciated.* >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/JbNTXjuud3IJ. For more options, visit https://groups.google.com/groups/opt_out.
AmateurCoder wrote in post #1095172:> I managed to get this to work. I used the fixture name instead of the > rigid > foreign key id in the capability_test.yml fixture. > > Thus, > > #fixtures > capability_types.yml > one: > name: MyString > capability_category: one > > two: > name: MyString > capability_category: oneGlad you got it going, but I just wanted to recommend you take a serious look at move away from fixtures to factories instead. https://github.com/thoughtbot/factory_girl_rails -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
And I suggest you do your best to minimize the use of factories/fixtures. In functional tests, you''ll want to limit your use of factories or fixtures only to the setup step for your functional tests. This way you''re only putting your application data in a specific state before you exercise the system. I''m assuming these are also end-to-end tests as well. ~Johnneylee On Feb 6, 2013 5:28 PM, "Robert Walker" <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> AmateurCoder wrote in post #1095172: > > I managed to get this to work. I used the fixture name instead of the > > rigid > > foreign key id in the capability_test.yml fixture. > > > > Thus, > > > > #fixtures > > capability_types.yml > > one: > > name: MyString > > capability_category: one > > > > two: > > name: MyString > > capability_category: one > > Glad you got it going, but I just wanted to recommend you take a serious > look at move away from fixtures to factories instead. > > https://github.com/thoughtbot/factory_girl_rails > > -- > Posted via http://www.ruby-forum.com/. > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit https://groups.google.com/groups/opt_out. > > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.