Sha256: cc784cae5edb5015ea1b4b709e1bd0be8cc4b6adb885b3698c584af66303f490

Contents?: true

Size: 1.64 KB

Versions: 3

Compression:

Stored size: 1.64 KB

Contents

describe Card::Set::Trait do
  class Card
    module Set
      module Type
        module Phrase
          extend Card::Set
          card_accessor :write, type: :pointer
          card_accessor :read, type_id: Card::PointerID
        end
      end

      module TypePlusRight
        module Phrase
          module Write
            extend Card::Set
            def type_plus_right_module_loaded
              true
            end
          end
        end
      end
    end
  end

  subject do
    Card::Auth.as_bot do
      Card.create! name: 'joke',
                   type_id: Card::PhraseID,
                   '+*write' => 'some content',
                   '+*read' => 'some content'
    end
  end

  context 'if accessor type is defined by a string' do
    it 'has left' do
      in_stage :prepare_to_validate, on: :create,
                                     trigger: -> { subject } do
        # test API doesn't support sets for event
        # so we check the name
        return unless name == 'joke'
        expect(write_card.left.class).to eq Card
      end
    end
    it 'loads *type plus right set module' do
      in_stage :prepare_to_validate, on: :create,
                                     trigger: -> { subject } do
        return unless name == 'joke'
        expect(write_card).to respond_to?(:type_plus_right_module_loaded)
      end
    end
  end
  context 'if accessor type is defined by an id' do
    it 'has left' do
      in_stage :prepare_to_validate, on: :create,
                                     trigger: -> { subject } do
        return unless name == 'joke'
        expect(read_card.left.class).to eq Card
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
card-1.18.6 spec/lib/card/set/trait_spec.rb
card-1.18.5 spec/lib/card/set/trait_spec.rb
card-1.18.4 spec/lib/card/set/trait_spec.rb