Hello! I''m trying to make a simple test. I have a "coming soon" page with a field where users can submit their emails. When the users clicks "submit" it should create a new record in the database. I Have two controllers: class PagesController < ApplicationController def home @newsletter_receiver = NewsletterReceiver.new end end And: class NewsletterReceiversController < ApplicationController def create @newsletter_receiver NewsletterReceiver.new(params[:newsletter_receiver]) if @newsletter_receiver.save flash[:notice] = "A message" redirect_to root_path else render ''pages/home'' end end end My NewsletterReceiversController specs looks like this: require ''spec_helper'' describe NewsletterReceiversController do describe "Success" do before(:each) do @attr = { :email => "example-hcDgGtZH8xNBDgjK7y7TUQ@public.gmane.org" } end it "should create a receiver" do lambda do post :create, :newsletter_reveiver => @attr end.should change(NewsletterReceiver, :count).by(1) end end end end This gives me the following error: Failure/Error: lambda do count should have been changed by 1, but was changed by 0 Anyone got any tips on how to solve this? Thanks // Anders -- 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 Apr 23, 8:58 pm, Anders_P <and...-TlBSdMGKk75YFVMCzM9+FrNAH6kLmebB@public.gmane.org> wrote:> Hello! > > > > And: > > class NewsletterReceiversController < ApplicationController > def create > @newsletter_receiver > NewsletterReceiver.new(params[:newsletter_receiver]) > if @newsletter_receiver.save > flash[:notice] = "A message" > redirect_to root_path > else > render ''pages/home'' > end > end > end > > My NewsletterReceiversController specs looks like this: > > require ''spec_helper'' > > describe NewsletterReceiversController do > > describe "Success" do > > before(:each) do > @attr = { :email => "exam...-hcDgGtZH8xNBDgjK7y7TUQ@public.gmane.org" } > end > > it "should create a receiver" do > lambda do > post :create, :newsletter_reveiver => @attr > end.should change(NewsletterReceiver, :count).by(1) > endStep through your code and you''ll see that you''ve got a typo here. Fred> end > end > end > > This gives me the following error: > > Failure/Error: lambda do > count should have been changed by 1, but was changed by 0 > > Anyone got any tips on how to solve this? > > Thanks > // Anders-- 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.
Ouch embarrassing. :D Thanks! On 23 Apr, 22:15, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Apr 23, 8:58 pm, Anders_P <and...-TlBSdMGKk75YFVMCzM9+FrNAH6kLmebB@public.gmane.org> wrote: > > > > > > > Hello! > > > And: > > > class NewsletterReceiversController < ApplicationController > > def create > > @newsletter_receiver > > NewsletterReceiver.new(params[:newsletter_receiver]) > > if @newsletter_receiver.save > > flash[:notice] = "A message" > > redirect_to root_path > > else > > render ''pages/home'' > > end > > end > > end > > > My NewsletterReceiversController specs looks like this: > > > require ''spec_helper'' > > > describe NewsletterReceiversController do > > > describe "Success" do > > > before(:each) do > > @attr = { :email => "exam...-hcDgGtZH8xNBDgjK7y7TUQ@public.gmane.org" } > > end > > > it "should create a receiver" do > > lambda do > > post :create, :newsletter_reveiver => @attr > > end.should change(NewsletterReceiver, :count).by(1) > > end > > Step through your code and you''ll see that you''ve got a typo here. > > Fred > > > > > end > > end > > end > > > This gives me the following error: > > > Failure/Error: lambda do > > count should have been changed by 1, but was changed by 0 > > > Anyone got any tips on how to solve this? > > > Thanks > > // Anders-- 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.