Sha256: d15dd213558af83b8f292d1a2362d6689079b156ba11f37ab65494afe15c9984

Contents?: true

Size: 1.82 KB

Versions: 36

Compression:

Stored size: 1.82 KB

Contents

package_require("ree_actions/dsl")

RSpec.describe ReeActions::DSL, type: [:autoclean] do
  link :build_sqlite_connection, from: :ree_dao

  before(:all) do
    connection = build_sqlite_connection({database: 'sqlite_db'})

    if connection.table_exists?(:users)
      connection.drop_table(:users)
    end

    if connection.table_exists?(:products)
      connection.drop_table(:products)
    end

    connection.create_table :users do
      primary_key :id

      column  :name, 'varchar(256)'
      column  :age, :integer
    end

    connection.disconnect
  end

  before do
    Ree.enable_irb_mode
  end

  after do
    Ree.disable_irb_mode
  end

  it {
    module ReeActionsTest
      include Ree::PackageDSL

      package do
        depends_on :ree_mapper
        depends_on :ree_dao
      end

      class TestAction
        include ReeActions::DSL

        action :test_action

        ActionCaster = build_mapper.use(:cast) do
          integer :user_id
        end

        contract Any, ActionCaster.dto(:cast) => Integer
        def call(user_access, attrs)
          attrs[:user_id]
        end
      end
    end

    result = ReeActionsTest::TestAction.new.call('user_access', {user_id: 1})
    expect(result).to eq(1)

    expect {
      ReeActionsTest::TestAction.new.call('user_access', {user_id: 'not integer'})
    }.to raise_error(ReeActions::ParamError)
  }

  it {
    module ReeActionsTest
      include Ree::PackageDSL

      package do
        depends_on :ree_mapper
        depends_on :ree_dao
      end

      class TestAction2
        include ReeActions::DSL

        action :test_action2

        contract Any, Hash => Integer
        def call(user_access, attrs)
          attrs[:user_id]
        end
      end
    end

    result = ReeActionsTest::TestAction2.new.call('user_access', {user_id: 1})
    expect(result).to eq(1)
  }
end

Version data entries

36 entries across 36 versions & 1 rubygems

Version Path
ree_lib-1.0.124 lib/ree_lib/packages/ree_actions/spec/ree_actions/dsl_spec.rb
ree_lib-1.0.123 lib/ree_lib/packages/ree_actions/spec/ree_actions/dsl_spec.rb
ree_lib-1.0.122 lib/ree_lib/packages/ree_actions/spec/ree_actions/dsl_spec.rb
ree_lib-1.0.121 lib/ree_lib/packages/ree_actions/spec/ree_actions/dsl_spec.rb
ree_lib-1.0.120 lib/ree_lib/packages/ree_actions/spec/ree_actions/dsl_spec.rb
ree_lib-1.0.119 lib/ree_lib/packages/ree_actions/spec/ree_actions/dsl_spec.rb
ree_lib-1.0.118 lib/ree_lib/packages/ree_actions/spec/ree_actions/dsl_spec.rb
ree_lib-1.0.117 lib/ree_lib/packages/ree_actions/spec/ree_actions/dsl_spec.rb
ree_lib-1.0.116 lib/ree_lib/packages/ree_actions/spec/ree_actions/dsl_spec.rb
ree_lib-1.0.115 lib/ree_lib/packages/ree_actions/spec/ree_actions/dsl_spec.rb
ree_lib-1.0.114 lib/ree_lib/packages/ree_actions/spec/ree_actions/dsl_spec.rb
ree_lib-1.0.113 lib/ree_lib/packages/ree_actions/spec/ree_actions/dsl_spec.rb
ree_lib-1.0.112 lib/ree_lib/packages/ree_actions/spec/ree_actions/dsl_spec.rb
ree_lib-1.0.111 lib/ree_lib/packages/ree_actions/spec/ree_actions/dsl_spec.rb
ree_lib-1.0.110 lib/ree_lib/packages/ree_actions/spec/ree_actions/dsl_spec.rb
ree_lib-1.0.109 lib/ree_lib/packages/ree_actions/spec/ree_actions/dsl_spec.rb
ree_lib-1.0.108 lib/ree_lib/packages/ree_actions/spec/ree_actions/dsl_spec.rb
ree_lib-1.0.107 lib/ree_lib/packages/ree_actions/spec/ree_actions/dsl_spec.rb
ree_lib-1.0.106 lib/ree_lib/packages/ree_actions/spec/ree_actions/dsl_spec.rb
ree_lib-1.0.105 lib/ree_lib/packages/ree_actions/spec/ree_actions/dsl_spec.rb