Saturday, April 23, 2011

[Rails] (Beginner) Learning Rspec (help!)

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@example.com" }
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@googlegroups.com.
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.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate