Sha256: b78d7abfc2710a73b05b911d7f8fae40dc7a9fd743f0760469a73413b9f06ffd

Contents?: true

Size: 1.52 KB

Versions: 6

Compression:

Stored size: 1.52 KB

Contents

module OpenStax
  module Accounts
    describe HasManyThroughGroups do
      let!(:account_1) { FactoryGirl.create(:openstax_accounts_account,
                         username: 'some_user',
                         openstax_uid: 1) }
      let!(:user_1)    { User.create(:account => account_1) }

      let!(:account_2) { FactoryGirl.create(:openstax_accounts_account,
                         username: 'another_user',
                         openstax_uid: 2) }
      let!(:user_2)    { User.create(:account => account_2) }

      let!(:group_nesting) { FactoryGirl.create(:openstax_accounts_group_nesting) }

      before(:each) do
        group_nesting.member_group.add_member(account_1)
      end

      it 'allows users to retrieve all nested has_many_through_groups objects' do
        expect(user_1.ownerships).to be_empty

        o = Ownership.new
        o.owner = user_2
        o.save!

        expect(user_1.reload.ownerships).to be_empty

        o2 = Ownership.new
        o2.owner = user_1
        o2.save!

        expect(user_1.reload.ownerships).to include(o2)

        o3 = Ownership.new
        o3.owner = group_nesting.member_group
        o3.save!

        expect(user_1.reload.ownerships).to include(o2)
        expect(user_1.ownerships).to include(o3)

        o4 = Ownership.new
        o4.owner = group_nesting.container_group
        o4.save!

        expect(user_1.reload.ownerships).to include(o2)
        expect(user_1.ownerships).to include(o3)
        expect(user_1.ownerships).to include(o4)
      end

    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
openstax_accounts-4.1.1 spec/lib/openstax/accounts/has_many_through_groups_spec.rb
openstax_accounts-4.1.0 spec/lib/openstax/accounts/has_many_through_groups_spec.rb
openstax_accounts-4.0.0 spec/lib/openstax/accounts/has_many_through_groups_spec.rb
openstax_accounts-3.1.1 spec/lib/openstax/accounts/has_many_through_groups_spec.rb
openstax_accounts-3.1.0 spec/lib/openstax/accounts/has_many_through_groups_spec.rb
openstax_accounts-3.0.0 spec/lib/openstax/accounts/has_many_through_groups_spec.rb