Sha256: d17ece64d697dad49a809a5fa039c4d7e2473c6edacb7af3a4fae91aab321e96

Contents?: true

Size: 1.95 KB

Versions: 27

Compression:

Stored size: 1.95 KB

Contents

require 'spec_helper'

module Upcasing
  def self.call(keys)
    keys.map {|key| key.to_s.upcase}
  end
end

describe RestModel::Source::Path do
  shared_examples_for "an input path" do
    it "brings the correct input path" do
      subject.source_path.should == path
    end
  end

  context "when a custom path is not defined" do
    context "and there is'nt a custom keys input converter" do
      subject    {RestModel::Key.new(:name)}
      let(:path) {[:name]}
      it_behaves_like "an input path"
    end

    context "and there is a custom keys input converter" do
      subject {RestModel::Key.new(:name, convert_input_keys: Upcasing)}
      let(:path) {['NAME']}
      it_behaves_like "an input path"
    end
  end

  context "when a custom path is defined" do
    context "and it is a simple name" do
      subject    {RestModel::Key.new(:name, field: :other_name)}
      let(:path) {[:other_name]}
      it_behaves_like "an input path"
    end

    context "and it is a set of names composed by dot" do
      subject    {RestModel::Key.new(:name, field: 'a.long.way.to.go')}
      let(:path) {['a', 'long', 'way', 'to', 'go']}
      it_behaves_like "an input path"
    end

    context "and it is a set of names composed by dot" do
      subject    {RestModel::Key.new(:name, field: 'a.long.long.way.to.go')}
      let(:path) {['a', 'long', 'long', 'way', 'to', 'go']}
      it_behaves_like "an input path"
    end

    context "and it is a set of names composed by dot using :start_key instead of :field" do
      subject    {RestModel::Key.new(:name, start_key: 'a.long.way.to.go')}
      let(:path) {['a', 'long', 'way', 'to', 'go']}
      it_behaves_like "an input path"
    end

    context "and there is a custom keys input converter" do
      let(:options) {{start_key: 'yay.upcase.path', convert_input_keys: Upcasing}}
      subject {RestModel::Key.new(:name, options)}
      let(:path) {['YAY', 'UPCASE', 'PATH']}
      it_behaves_like "an input path"
    end
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
rest_model-0.2.1 spec/unit/source/path_spec.rb
rest_model-0.2.0 spec/unit/source/path_spec.rb
rest_model-0.1.24 spec/unit/source/path_spec.rb
rest_model-0.1.23 spec/unit/source/path_spec.rb
rest_model-0.1.22 spec/unit/source/path_spec.rb
rest_model-0.1.21 spec/unit/source/path_spec.rb
rest_model-0.1.20 spec/unit/source/path_spec.rb
rest_model-0.1.19 spec/unit/source/path_spec.rb
rest_model-0.1.18 spec/unit/source/path_spec.rb
rest_model-0.1.17 spec/unit/source/path_spec.rb
rest_model-0.1.16 spec/unit/source/path_spec.rb
rest_model-0.1.15 spec/unit/source/path_spec.rb
rest_model-0.1.14 spec/unit/source/path_spec.rb
rest_model-0.1.13 spec/unit/source/path_spec.rb
rest_model-0.1.12 spec/unit/source/path_spec.rb
rest_model-0.1.11 spec/unit/source/path_spec.rb
rest_model-0.1.10 spec/unit/source/path_spec.rb
rest_model-0.1.9 spec/unit/source/path_spec.rb
rest_model-0.1.8 spec/unit/source/path_spec.rb
rest_model-0.1.7 spec/unit/source/path_spec.rb