Sha256: d75b4d6be81fce011761f53306c0fa8a2291b11a48b39bbc45fd0ca0f459e29f

Contents?: true

Size: 1.63 KB

Versions: 6

Compression:

Stored size: 1.63 KB

Contents

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

module Troo
  describe MemberPersistence do
    let(:described_class) { MemberPersistence }
    let(:resource) { OpenStruct.new({
      id:        "5195fdb5a8c01a2318004f5d",
      full_name: resource_full_name
    }) }
    let(:resource_full_name) { "My Test Member" }
    let(:options) { { } }

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

    describe ".initialize" do
      subject { described_class.new(resource, options) }

      it "assigns the resource to an instance variable" do
        subject.instance_variable_get("@resource").must_equal(resource)
      end

      it "assigns the options to an instance variable" do
        subject.instance_variable_get("@options").must_equal(options)
      end
    end

    describe "#persist" do
      subject { described_class.for(resource, options) }

      context "when there is already a local copy" do
        context "and the local copy is identical" do
          it "returns the local copy" do
            subject.must_equal(@member)
          end
        end

        context "and the local copy is out of date" do
          let(:resource_full_name) { "My Renamed Member" }

          it "updates and returns the new local copy" do
            subject.full_name.must_equal(resource_full_name)
          end
        end
      end

      context "when there is not already a local copy" do
        let(:resource_full_name) { "My New Test Member" }

        before { database_cleanup }

        it "creates and returns the new local copy" do
          subject.full_name.must_equal(resource_full_name)
        end
      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_persistence_test.rb
troo-0.0.6 test/lib/troo/models/member_persistence_test.rb
troo-0.0.5 test/lib/troo/models/member_persistence_test.rb
troo-0.0.4 test/lib/troo/models/member_persistence_test.rb
troo-0.0.3 test/lib/troo/models/member_persistence_test.rb
troo-0.0.2 test/lib/troo/models/member_persistence_test.rb