Continuing on my quest to learn rspec

Ok,

So… My first attempt at specing a method in my photo model didn’t go
so
well…

Both of these tests are failing, and I am not even sure if I am
structuring
this anywhere near correct or not…

In other words… HELP!!!

Patrick J. Collins
http://collinatorstudios.com

On 23 Mar 2010, at 17:43, Patrick J. Collins wrote:

this anywhere near correct or not…

In other words… HELP!!!

Patrick J. Collins
http://collinatorstudios.com

Okay I have a few thoughts for you Patrick, hopefully I’ll be able to
give you them in an order that makes some sense.

Firstly I wonder why you’re putting this behaviour on the photo class.
Have you ever heard of the code smell ‘feature envy’? Photo#set_cover
seems to me to be talking mostly to the photo_album, so perhaps this
behaviour should move there?

Something like

Also, I’m not seeing anything in the specs that actually triggers any
behaviour in the class. You set up a stub and then immediately assert
what the photo album’s cover should be - when are you expecting the
code you want to test to be caused to actually run?


rspec-users mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/rspec-users

cheers,
Matt

+447974 430184

Firstly I wonder why you’re putting this behaviour on the photo class. Have
you ever heard of the code smell ‘feature envy’? Photo#set_cover seems to me
to be talking mostly to the photo_album, so perhaps this behaviour should move
there?

Ok… So I changed that code and put it in my photos_controller, and I
took
the gist you wrote, and modified it to what I think the behavior
should be.

I still am very much struggling as to what I am doing…

So, let me explain my idea of the behavior I am imagining, and see if
perhaps
you guys can guide me as to how I should be thinking, etc.

Ok… So… Form field, checkbox_tag :photo_album_cover… If it’s
checked,
when the photo is saved, it should set that photo to be the cover for
the photo
album.

If it’s not checked, and no cover is currently set, it should set the
cover to
the first photo in the album.

If it’s not checked, and this currently save photo is the only photo in
the
album, then it is ‘the first photo in the album’, and therefore it
should be
the cover.

That’s the basis for this “behavior”…

So, what am I doing wrong as far as my spec goes, because I am getting:

‘PhotoAlbum saving a photo should set the cover of the album to the
curent
photo when ‘album cover’ is checked’ FAILED
expected: #<Photo id: 1002, description: nil, name: nil,
access_level_id: nil,
photo_album_id: 1, image_height: nil, image_width: nil, server_format:
nil,
image_filename: nil, photo_album_cover_id: nil, position: nil,
contact_id: nil,
event_id: nil, media_id: nil, created_at: nil, updated_at: nil>,
got: nil (using ==)

Thank you in advance for your patience and guidance!

Patrick J. Collins
http://collinatorstudios.com