Sha256: c00acd0c30565ac5dfdaa9bdc0bf3498a9876271b77d42c38660e4e317c7b529

Contents?: true

Size: 1.6 KB

Versions: 17

Compression:

Stored size: 1.6 KB

Contents

require "spec_helper"


describe Shamu::Services::Request do
  describe ".model_name" do
    {
      "Users::UserRequest::Create" => "Users::User",
      "Users::UserRequest::New" => "Users::User",
      "Users::UserRequest::Change" => "Users::User",
      "Users::UserRequest::Update" => "Users::User",
      "Users::Request::Change" => "Users::User",
      "Users::FavoritesUpdate" => "Users::Favorite",
      "Users::FavoritesCreate" => "Users::Favorite",
      "Users::FavoritesChange" => "Users::Favorite",
      "Users::FavoritesNew" => "Users::Favorite",
      "UserUpdateRequest" => "User"
    }.each do |name, model_name|
      it "formats '#{ name }' as '#{ model_name }'" do
        klass = Class.new( Shamu::Services::Request )
        klass.define_singleton_method :name do
          name
        end

        expect( klass.model_name.name ).to eq model_name
      end
    end
  end

  describe "#apply_to" do
    let( :klass ) do
      Class.new( Shamu::Services::Request ) do
        attribute :name
        attribute :label
      end
    end
    let( :request ) { klass.new name: "Example" }

    it "returns the model" do
      model = double
      expect( Shamu::Services::Request.new.apply_to( model ) ).to be model
    end

    it "assigns attributes that have been set" do
      model = double( name: "", label: "" )
      expect( model ).to receive( :name= ).with( any_args )

      request.apply_to( model )
    end

    it "skips attributes that haven't been set" do
      model = double( name: "", label: "" )
      expect( model ).not_to receive( :label= )

      request.apply_to( model )
    end
  end

end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
shamu-0.0.24 spec/lib/shamu/services/request_spec.rb
shamu-0.0.21 spec/lib/shamu/services/request_spec.rb
shamu-0.0.20 spec/lib/shamu/services/request_spec.rb
shamu-0.0.19 spec/lib/shamu/services/request_spec.rb
shamu-0.0.18 spec/lib/shamu/services/request_spec.rb
shamu-0.0.17 spec/lib/shamu/services/request_spec.rb
shamu-0.0.15 spec/lib/shamu/services/request_spec.rb
shamu-0.0.14 spec/lib/shamu/services/request_spec.rb
shamu-0.0.13 spec/lib/shamu/services/request_spec.rb
shamu-0.0.11 spec/lib/shamu/services/request_spec.rb
shamu-0.0.9 spec/lib/shamu/services/request_spec.rb
shamu-0.0.8 spec/lib/shamu/services/request_spec.rb
shamu-0.0.7 spec/lib/shamu/services/request_spec.rb
shamu-0.0.5 spec/lib/shamu/services/request_spec.rb
shamu-0.0.4 spec/lib/shamu/services/request_spec.rb
shamu-0.0.3 spec/lib/shamu/services/request_spec.rb
shamu-0.0.2 spec/lib/shamu/services/request_spec.rb