Created
June 9, 2012 09:58
-
-
Save tadyjp/2900349 to your computer and use it in GitHub Desktop.
[rails] has_many association; collection count, size and length
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# in user model: | |
# has_many :pins_relationship, class_name: 'Action', conditions: {kind: 'pin'} | |
# has_many :pins, through: :pins_relationship, source: :stuff, uniq: true | |
it "pin place (duplicate check)" do | |
@alice.pins << Stuff.find_or_create_by_kind_and_name!(kind: 'landmark', name: "お気に入り喫茶店") | |
@alice.pins << Stuff.find_or_create_by_kind_and_name!(kind: 'landmark', name: "お気に入り喫茶店") | |
@alice.pins.where(kind: 'landmark', name: "お気に入り喫茶店").count.should == 2 | |
@alice.pins.where(kind: 'landmark', name: "お気に入り喫茶店").size.should == 2 | |
@alice.pins.where(kind: 'landmark', name: "お気に入り喫茶店").length.should == 1 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment