Sha256: 15d022ad32de2ac3a910e58646862b4f95e75568c60e54677e8b57df68e304f8
Contents?: true
Size: 1.44 KB
Versions: 11
Compression:
Stored size: 1.44 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 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 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
11 entries across 11 versions & 1 rubygems