When POST :create check values of the object that was created

4 views
Skip to first unread message

rtacconi

unread,
Jul 23, 2010, 5:28:31 AM7/23/10
to shoulda
I want to check that the create method creates and object with one
attribute set to a particular value. In this case I want to check:

assert_equal @p.user_type, 'MODERATOR'

The problem is that I am trying to load an object but it is always
nil. I tried that query in the console and it is ok. Is there
something that I am missing?

(I am using factory girl for the testing data)

-------------------------------------
Full code:

class ParticipationControllerTest < ActionController::TestCase
context "on POST to :create" do
setup do
@configuration_panel = Factory.create :configuration, :status =>
'PANEL'
@configuration_live = Factory.create :configuration,
:status => 'LIVE',
:panel_id =>
@configuration_panel.id
@bernie = Factory.create :participant,
:name => 'Bernie X',
:email => 'ber...@email.com'

post :create, :participation => { :participant_id => @bernie.id,
:configuration_id =>
@configuration_live.id }
end

should assign_to :participation
should respond_with :success
@bernie = Participant.find_by_email 'ber...@email.com'
@p = Participation.find_by_participant_id @bernie.id

# bernie is the first host so it should be automatically a
moderator
assert_equal @p.user_type, 'MODERATOR'
end
end

Curran Schiefelbein

unread,
Aug 4, 2010, 12:35:56 PM8/4/10
to sho...@googlegroups.com
Why not wrap those assignments and the assert_equal inside a should
block? They seem to be wandering around loose in the context block.

Curran

> --
> Individuals over processes. Interactions over tools.
>
> Agile Rails training from thoughtbot, the makers of Clearance, Shoulda, & Factory Girl:
> http://thoughtbot.com/services/training
>
> The Shoulda group:
> http://groups.google.com/group/shoulda
>
> To post to this group, send email to
> sho...@googlegroups.com
>
> To unsubscribe from this group, send email to
> shoulda+u...@googlegroups.com

Riccardo Tacconi

unread,
Aug 4, 2010, 1:22:59 PM8/4/10
to sho...@googlegroups.com
I will do that
--
Riccardo Tacconi
Web developer at Wolseley UK

http://www.linkedin.com/in/riccardotacconi
http://riccardotacconi.blogspot.com/
http://twitter.com/rtacconi
Linux user: #400461
Reply all
Reply to author
Forward
0 new messages