Skip to content

Instantly share code, notes, and snippets.

@tadyjp
Created June 9, 2012 09:58
Show Gist options
  • Save tadyjp/2900349 to your computer and use it in GitHub Desktop.
Save tadyjp/2900349 to your computer and use it in GitHub Desktop.
[rails] has_many association; collection count, size and length
# 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