Sha256: 29507f46f278a9d20f4721fb484dbb4f7dc5187296d03824179e9b3d86862268

Contents?: true

Size: 1.47 KB

Versions: 6

Compression:

Stored size: 1.47 KB

Contents

require_relative "../../../test_helper"

module Troo
  describe MemberRetrieval do
    let(:described_class) { MemberRetrieval }
    let(:full_name) { "My Test Member" }

    before { @member = Fabricate(:member, full_name: full_name) }
    after  { database_cleanup }

    describe ".all" do
      subject { described_class.all }

      it "retrieves all locally stored members" do
        subject.size.must_equal 1
      end
    end

    describe ".retrieve" do
      subject { described_class.retrieve(id) }

      context "local retrieval by database ID" do
        let(:id) { @member.id }

        it "returns the correct member" do
          subject.full_name.must_equal("My Test Member")
        end
      end

      context "local retrieval by external ID" do
        let(:id) { "5195fdb5a8c01a2318004f5d" }

        it "returns the correct member" do
          subject.full_name.must_equal("My Test Member")
        end
      end

      context "remote retrieval by either ID" do
        let(:id) { "526d_remote_member_005259" }
        let(:full_name) { "My Remote Test Member" }

        before { External::Member.stubs(:fetch).returns([@member]) }

        it "returns the correct member" do
          subject.full_name.must_equal("My Remote Test Member")
        end
      end

      context "when the ID cannot be found" do
        let(:id) { "not_found_id" }

        before { External::Member.stubs(:fetch).returns([]) }

        it { subject.must_equal(nil) }
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
troo-0.0.7 test/lib/troo/models/member_retrieval_test.rb
troo-0.0.6 test/lib/troo/models/member_retrieval_test.rb
troo-0.0.5 test/lib/troo/models/member_retrieval_test.rb
troo-0.0.4 test/lib/troo/models/member_retrieval_test.rb
troo-0.0.3 test/lib/troo/models/member_retrieval_test.rb
troo-0.0.2 test/lib/troo/models/member_retrieval_test.rb