require 'rails_helper' RSpec.describe OrgBranch, type: :model do before do @org = Org.create!(lang_id: 1) end describe ".has_member" do before do @branch = OrgBranch.create!(org_id: @org.id, org_branch_type_id: 1) @branch2 = OrgBranch.create!(org_id: @org.id, org_branch_type_id: 1) end it "count 0" do expect(OrgBranch.has_member.first).to be_nil end it "count 1 with 1 member" do @branch.add OrgMember.create!(org_id: @org.id, entried_on: Time.now) expect(OrgBranch.has_member.first.id).to eq(@branch.id) end it "count 1 with 2 member" do @branch.add OrgMember.create!(org_id: @org.id, entried_on: Time.now) @branch.add OrgMember.create!(org_id: @org.id, entried_on: Time.now) expect(OrgBranch.has_member.count).to eq(1) expect(OrgBranch.has_member.first.id).to eq(@branch.id) end end end