Sha256: f2a5532eabfdf7fbb11481bad4d70deadeb0ed9f27c552a261b0a2e4d2ca6a7a

Contents?: true

Size: 1.36 KB

Versions: 13

Compression:

Stored size: 1.36 KB

Contents

require 'spec_helper'

RSpec.describe 'client' do
  context 'with specific architecture' do
    it 'allows module-based interfaces' do
      class ModuleClient
        include Cistern::Client.with(interface: :module)
      end

      class ModuleClient::Shoot
        include ModuleClient::Request

        def real(mod)
          mod % 9
        end
      end

      class ModuleClient::Moon
        include ModuleClient::Model

        identity :on

        def save
          identity % 3
        end
      end

      class ModuleClient::Moons
        include ModuleClient::Collection

        model ModuleClient::Moon
      end

      expect(
        ModuleClient.new.shoot(12)
      ).to eq(3)

      expect(ModuleClient.collections).to contain_exactly(ModuleClient::Moons)
      expect(ModuleClient.models).to contain_exactly(ModuleClient::Moon)
      expect(ModuleClient.requests).to contain_exactly(ModuleClient::Shoot)

      expect(
        ModuleClient.new.moons.new(on: 5).save
      ).to eq(2)
    end

    it 'allows custom model interface' do
      class AskClient
        include Cistern::Client.with(model: 'Ask', interface: :module)
      end

      class AskClient::Model
        include AskClient::Ask

        identity :id

        def save
          9 % identity
        end
      end

      expect(
        AskClient.new.model(id: 9).save
      ).to eq(0)
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
cistern-2.8.0 spec/client_spec.rb
cistern-2.7.2 spec/client_spec.rb
cistern-2.7.1 spec/client_spec.rb
cistern-2.7.0 spec/client_spec.rb
cistern-2.6.0 spec/client_spec.rb
cistern-2.5.0 spec/client_spec.rb
cistern-2.4.1 spec/client_spec.rb
cistern-2.4.0 spec/client_spec.rb
cistern-2.3.0 spec/client_spec.rb
cistern-2.2.7 spec/client_spec.rb
cistern-2.2.6 spec/client_spec.rb
cistern-2.2.5 spec/client_spec.rb
cistern-2.2.4 spec/client_spec.rb