Sha256: 462ce1ea49e0deaacec41824da521c42664abee048d07025434378c20315b8b7
Contents?: true
Size: 1.71 KB
Versions: 3
Compression:
Stored size: 1.71 KB
Contents
require 'test_helper' describe Relation do let(:user) { User.create! name: 'user' } let(:user2) { User.create! name: 'user2' } let(:order) { Order.create! name: 'order' } let(:order2) { Order.create! name: 'order2' } def setup DB.setup Relation.add user, order Relation.add user2, order Relation.add user2, order2 end def teardown DB.teardown end it "should add a connection" do assert_difference('Relation.count') do Relation.add user2, user end end it "should delete a connection" do Relation.add user2, user assert_difference('Relation.count', -1) do Relation.delete user2, user end end it "should return references (using class name)" do arr = Relation.references(user, 'Order') assert_equal [order].sort, arr.sort arr = Relation.references(user2, 'Order') assert_equal [order, order2].sort, arr.sort end it "should return references (using class)" do arr = Relation.references(user, Order) assert_equal [order].sort, arr.sort end it "should return followers (using class name)" do arr = Relation.followers('User', order) assert_equal [user, user2].sort, arr.sort arr = Relation.followers('User', order2) assert_equal [user2].sort, arr.sort end it "should return followers (using class)" do arr = Relation.followers(User, order) assert_equal [user, user2].sort, arr.sort end it "should not add twice the same connection" do assert_difference('Relation.count') do Relation.add user2, user Relation.add user2, user end end it "should handle unexistent connection" do assert_difference('Relation.count', 0) do Relation.delete user2, user end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
relation-0.1.5 | test/relation_test.rb |
relation-0.1.3 | test/relation_test.rb |
relation-0.1.1 | test/relation_test.rb |