Sha256: 0fd24a724c96d3d65c90ef23c463621988ae4cb0c0b0f533dd5112cebd39902b

Contents?: true

Size: 1.91 KB

Versions: 15

Compression:

Stored size: 1.91 KB

Contents

RSpec.describe "EitilWrapper::Decorators" do

  include Rack::Test::Methods

  let(:user) { User.create(first_name: 'slim', last_name: 'shady') }

  def body(endpoint)
    @body ||= JSON.parse(get("/users/#{user.id}/#{endpoint}").body)
  end

  it "should respond to a request" do   
    response = get "/users/#{user.id}/decorator_a"
    expect(response).to be_a Rack::MockResponse
  end

  it "should, by default, return all of a records' columns" do
    response_keys = body(:decorator_a).keys.map(&:to_sym)
    table_columns = [:id, :created_at, :updated_at, :first_name, :last_name, :email, :birthday, :phone, :confirmed, :last_sign_in, :age, :wage]
    expect(table_columns.all? { |column| response_keys.include?(column) }).to be_truthy
  end

  it "should, if a specific decorator method is passed, return that method's value" do
    response_keys  = body(:decorator_b).keys.map(&:to_sym)
    decorator_keys = [:first_name, :last_name]
    expect(response_keys).to eq decorator_keys
  end

  it "should, if no decorator method is passed, but param['isMobile'] is present, return the :app method's value" do
    response       = post "/users/#{user.id}/decorator_c", { "isMobile" => true }
    response_keys  = JSON.parse(response.body).keys.map(&:to_sym)
    decorator_keys = [:phone, :email]
    expect(response_keys).to eq decorator_keys
  end

  it "should, if no decorator method is passed, but param['isWeb'] is present, return the :web method's value" do
    response       = post "/users/#{user.id}/decorator_c", { "isWeb" => true }
    response_keys  = JSON.parse(response.body).keys.map(&:to_sym)
    decorator_keys = [:age, :wage]
    expect(response_keys).to eq decorator_keys
  end

  it "should, if a decorator class is passed, return the value of that class' method" do
    response_keys  = body(:decorator_d).keys.map(&:to_sym)
    decorator_keys = [:created_at, :updated_at]
    expect(response_keys).to eq decorator_keys
  end
  
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
eitil-1.4.1 spec/eitil_wrapper/decorators/decorators_spec.rb
eitil-1.4.0 spec/eitil_wrapper/decorators/decorators_spec.rb
eitil-1.3.12 spec/eitil_wrapper/decorators/decorators_spec.rb
eitil-1.3.11 spec/eitil_wrapper/decorators/decorators_spec.rb
eitil-1.3.10 spec/eitil_wrapper/decorators/decorators_spec.rb
eitil-1.3.9 spec/eitil_wrapper/decorators/decorators_spec.rb
eitil-1.3.8 spec/eitil_wrapper/decorators/decorators_spec.rb
eitil-1.3.7 spec/eitil_wrapper/decorators/decorators_spec.rb
eitil-1.3.6 spec/eitil_wrapper/decorators/decorators_spec.rb
eitil-1.3.5 spec/eitil_wrapper/decorators/decorators_spec.rb
eitil-1.3.4 spec/eitil_wrapper/decorators/decorators_spec.rb
eitil-1.3.3 spec/eitil_wrapper/decorators/decorators_spec.rb
eitil-1.3.2 spec/eitil_wrapper/decorators/decorators_spec.rb
eitil-1.3.1 spec/eitil_wrapper/decorators/decorators_spec.rb
eitil-1.3.0 spec/eitil_wrapper/decorators/decorators_spec.rb