In controller I have: def search unless params[:data_search].blank? shop_data = params[:data_search] @shops = Shop.data_search(shop_data).paginate(:per_page => Settings.shops_per_page, :page => params[:page]) else @shops = Shop.all.paginate(:per_page => Settings.shops_per_page, :page => params[:page]) end render :layout => false if request.xhr? end In controller.spec I have: def mock_shop(stubs={}) @mock_shop ||= mock_model(Shop, stubs).as_null_object end describe "search" do context "when name is ''Test''" do it "should find shops" do @name = "Test" Shop.stub(:search).with(@name) { [mock_shop] } get :search, :name => @name assigns(:shops).should eq([mock_shop]) end end end The failure is: Failure/Error: assigns(:shops).should eq([mock_shop]) expected [#<Shop:0x9f4 @name="Shop_1032">] got [] (compared using ==) Diff: @@ -1,2 +1,2 @@ -[#<Shop:0x9f4 @name="Shop_1032">] +[] What I am doing wrong? -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
get :search, :name => @name and in controller data_search is expected to be present. 2011/5/7 Mauro <mrsanna1-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>> In controller I have: > > def search > unless params[:data_search].blank? > shop_data = params[:data_search] > @shops = Shop.data_search(shop_data).paginate(:per_page => > Settings.shops_per_page, :page => params[:page]) > else > @shops = Shop.all.paginate(:per_page => Settings.shops_per_page, > :page => params[:page]) > end > render :layout => false if request.xhr? > end > > In controller.spec I have: > > def mock_shop(stubs={}) > @mock_shop ||= mock_model(Shop, stubs).as_null_object > end > > > describe "search" do > context "when name is ''Test''" do > it "should find shops" do > @name = "Test" > Shop.stub(:search).with(@name) { [mock_shop] } > get :search, :name => @name > assigns(:shops).should eq([mock_shop]) > end > end > end > > > The failure is: > > Failure/Error: assigns(:shops).should eq([mock_shop]) > > expected [#<Shop:0x9f4 @name="Shop_1032">] > got [] > > (compared using ==) > > Diff: > @@ -1,2 +1,2 @@ > -[#<Shop:0x9f4 @name="Shop_1032">] > +[] > > What I am doing wrong? > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 7 May 2011 19:16, Gintautas Šimkus <dihitales-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> get :search, :name => @name > > and in controller data_search is expected to be present.Yes, parameter is wrong but putting get :search, :data_search => @name I have the same failure. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 7 May 2011, at 18:08, Mauro <mrsanna1-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> describe "search" do > context "when name is ''Test''" do > it "should find shops" do > @name = "Test" > Shop.stub(:search).with(@name) { [mock_shop] } > get :search, :name => @name > assigns(:shops).should eq([mock_shop]) > end > end > end > > > The failure is: > > Failure/Error: assigns(:shops).should eq([mock_shop]) > > expected [#<Shop:0x9f4 @name="Shop_1032">] > got [] > > (compared using ==) > > Diff: > @@ -1,2 +1,2 @@ > -[#<Shop:0x9f4 @name="Shop_1032">] > +[] > > What I am doing wrong?It doesn''t look like you''re calling the stubbed method Fred> > -- > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 7 May 2011 20:35, Frederick Cheung <frederick.cheung-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > On 7 May 2011, at 18:08, Mauro <mrsanna1-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> describe "search" do >> context "when name is ''Test''" do >> it "should find shops" do >> @name = "Test" >> Shop.stub(:search).with(@name) { [mock_shop] } >> get :search, :name => @name >> assigns(:shops).should eq([mock_shop]) >> end >> end >> end >> >> >> The failure is: >> >> Failure/Error: assigns(:shops).should eq([mock_shop]) >> >> expected [#<Shop:0x9f4 @name="Shop_1032">] >> got [] >> >> (compared using ==) >> >> Diff: >> @@ -1,2 +1,2 @@ >> -[#<Shop:0x9f4 @name="Shop_1032">] >> +[] >> >> What I am doing wrong? > > It doesn''t look like you''re calling the stubbed methodCan you suggest how can I solve? -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 7 May 2011 23:05, Mauro <mrsanna1-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 7 May 2011 20:35, Frederick Cheung <frederick.cheung-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> >> >> On 7 May 2011, at 18:08, Mauro <mrsanna1-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> >>> describe "search" do >>> context "when name is ''Test''" do >>> it "should find shops" do >>> @name = "Test" >>> Shop.stub(:search).with(@name) { [mock_shop] } >>> get :search, :name => @name >>> assigns(:shops).should eq([mock_shop]) >>> end >>> end >>> end >>> >>> >>> The failure is: >>> >>> Failure/Error: assigns(:shops).should eq([mock_shop]) >>> >>> expected [#<Shop:0x9f4 @name="Shop_1032">] >>> got [] >>> >>> (compared using ==) >>> >>> Diff: >>> @@ -1,2 +1,2 @@ >>> -[#<Shop:0x9f4 @name="Shop_1032">] >>> +[] >>> >>> What I am doing wrong? >> >> It doesn''t look like you''re calling the stubbed method > > Can you suggest how can I solve?Sorry I''ve solved the error was Shop.stub(:search), it must be Shop.stub(:data_search) sorry for the noise. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.