Sha256: 093ef12c416d7ec66012cfb219e8de85288ac48af1361afd6775833e9be9ffb7

Contents?: true

Size: 1.85 KB

Versions: 8

Compression:

Stored size: 1.85 KB

Contents

require "spec_helper"

feature "Fill existing objects", %q{
   In order to use this lib with pre created objects
   as a lib user
   I want to be able to fill exiting objects instead of create a new one
} do

  given(:new_user_class){
    Yaoc::Helper::StructHE(:id, :firstname, :lastname, :roles)
  }

  given(:old_user_class){
    Yaoc::Helper::StructHE(:o_id, :o_firstname, :o_lastname)
  }

  given(:user_converter){

    Yaoc::ObjectMapper.new(new_user_class, old_user_class).tap do |mapper|
      mapper.add_mapping do
        fetcher :public_send

        rule to:   [:id, :firstname, :lastname],
             from: [:o_id, :o_firstname, :o_lastname]

      end
    end
  }

  given(:expected_new_user) {
    new_user_class.new(
        id: "user_1",
        firstname: "o firstname",
        lastname: "o lastname",
        roles: "admin, ruth, guest"
    )
  }

  given(:existing_user){
    new_user_class.new(
        id: nil,
        firstname: nil,
        lastname: nil,
        roles: "admin, ruth, guest"
    )
  }

  given(:existing_old_user){
    old_user_class.new(
        o_id: "existing_user_2",
        o_firstname: "o existing_firstname",
        o_lastname: "o existing_lastname"
    )
  }

  given(:old_user) {
    old_user_class.new(
        o_id: "user_1",
        o_firstname: "o firstname",
        o_lastname: "o lastname"

    )
  }

  scenario "creates an result object from an input_object" do
    conversion_result = user_converter.load(old_user, existing_user)

    expect(conversion_result.object_id).to eq existing_user.object_id
    expect(conversion_result).to eq expected_new_user
  end

  scenario "dumps an result object as result object" do
    conversion_result = user_converter.dump(expected_new_user, existing_old_user)

    expect(conversion_result.object_id).to eq existing_old_user.object_id
    expect(conversion_result).to eq old_user
  end

end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
yaoc-0.0.13 spec/acceptance/fill_existing_objects_spec.rb
yaoc-0.0.12 spec/acceptance/fill_existing_objects_spec.rb
yaoc-0.0.11 spec/acceptance/fill_existing_objects_spec.rb
yaoc-0.0.10 spec/acceptance/fill_existing_objects_spec.rb
yaoc-0.0.9 spec/acceptance/fill_existing_objects_spec.rb
yaoc-0.0.8 spec/acceptance/fill_existing_objects_spec.rb
yaoc-0.0.7 spec/acceptance/fill_existing_objects_spec.rb
yaoc-0.0.6 spec/acceptance/fill_existing_objects_spec.rb