Skip to content

Instantly share code, notes, and snippets.

@mrnugget
Created December 22, 2011 14:18
Show Gist options
  • Save mrnugget/1510445 to your computer and use it in GitHub Desktop.
Save mrnugget/1510445 to your computer and use it in GitHub Desktop.
#sessin_spec.rb
describe "Song associations" do
before(:each) do
@session = Session.create(:session_date => Time.now.to_date)
end
it "should have a songs attribute" do
@session.should respond_to(:songs)
end
it "should validate :songs" do
@session.songs.build(:file_name => "dude.bmp")
@session.should_not be_valid
end
it "should show songs in the right order" do
song1 = @session.songs.create!(:file_name => "03.testing.mp3")
song2 = @session.songs.create!(:file_name => "01.testing.mp3")
@session.songs.should == [song2, song1]
end
end
end
## Rspec
(~/rails/the_archive) mrnugget@jaggermeister $ rspec spec/models/session_spec.rb
.....F
Failures:
1) Session Song associations should show songs in the right order
Failure/Error: @session.songs.should == [song2, song1]
expected: [#<Song id: 2, file_name: "01.testing.mp3", session_id: 1, created_at: "2011-12-22 14:14:18", updated_at: "2011-12-22 14:14:18">, #<Song id: 1, file_name: "03.testing.mp3", session_id: 1, created_at: "2011-12-22 14:14:18", updated_at: "2011-12-22 14:14:18">]
got: [#<Song id: 1, file_name: "03.testing.mp3", session_id: 1, created_at: "2011-12-22 14:14:18", updated_at: "2011-12-22 14:14:18">, #<Song id: 2, file_name: "01.testing.mp3", session_id: 1, created_at: "2011-12-22 14:14:18", updated_at: "2011-12-22 14:14:18">] (using ==)
Diff:
@@ -1,3 +1,3 @@
-[#<Song id: 2, file_name: "01.testing.mp3", session_id: 1, created_at: "2011-12-22 14:14:18", updated_at: "2011-12-22 14:14:18">,
- #<Song id: 1, file_name: "03.testing.mp3", session_id: 1, created_at: "2011-12-22 14:14:18", updated_at: "2011-12-22 14:14:18">]
+[#<Song id: 1, file_name: "03.testing.mp3", session_id: 1, created_at: "2011-12-22 14:14:18", updated_at: "2011-12-22 14:14:18">,
+ #<Song id: 2, file_name: "01.testing.mp3", session_id: 1, created_at: "2011-12-22 14:14:18", updated_at: "2011-12-22 14:14:18">]
# ./spec/models/session_spec.rb:53:in `block (3 levels) in <top (required)>'
Finished in 0.93535 seconds
6 examples, 1 failure
Failed examples:
rspec ./spec/models/session_spec.rb:49 # Session Song associations should show songs in the right order
## Shell
(~/rails/the_archive) mrnugget@jaggermeister $ tail -f log/test.log
SQL (0.7ms) SELECT name
FROM sqlite_master
WHERE type = 'table' AND NOT name = 'sqlite_sequence'
AREL (1.4ms) INSERT INTO "sessions" ("session_date", "created_at", "updated_at") VALUES ('2011-12-22', '2011-12-22 14:14:18.271511', '2011-12-22 14:14:18.271511')
AREL (0.7ms) INSERT INTO "sessions" ("session_date", "created_at", "updated_at") VALUES ('2011-12-22', '2011-12-22 14:14:18.735477', '2011-12-22 14:14:18.735477')
AREL (0.8ms) INSERT INTO "sessions" ("session_date", "created_at", "updated_at") VALUES ('2011-12-22', '2011-12-22 14:14:18.746474', '2011-12-22 14:14:18.746474')
AREL (0.8ms) INSERT INTO "sessions" ("session_date", "created_at", "updated_at") VALUES ('2011-12-22', '2011-12-22 14:14:18.796042', '2011-12-22 14:14:18.796042')
AREL (0.4ms) INSERT INTO "songs" ("file_name", "session_id", "created_at", "updated_at") VALUES ('03.testing.mp3', 1, '2011-12-22 14:14:18.804877', '2011-12-22 14:14:18.804877')
AREL (0.3ms) INSERT INTO "songs" ("file_name", "session_id", "created_at", "updated_at") VALUES ('01.testing.mp3', 1, '2011-12-22 14:14:18.824310', '2011-12-22 14:14:18.824310')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment