Sha256: 3df2de891b2bc53f036890cfb66b1012c57631232101919cfe1d4798bea5bcfc

Contents?: true

Size: 1.93 KB

Versions: 17

Compression:

Stored size: 1.93 KB

Contents

require 'spec_helper'

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

describe Resource::InputPath do
  shared_examples_for "an input path" do
    it "brings the correct input path" do
      subject.input_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    {Resource::Key.new(:name)}
      let(:path) {[:name]}
      it_behaves_like "an input path"
    end

    context "and there is a custom keys input converter" do
      subject {Resource::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    {Resource::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    {Resource::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    {Resource::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    {Resource::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 {Resource::Key.new(:name, options)}
      let(:path) {['YAY', 'UPCASE', 'PATH']}
      it_behaves_like "an input path"
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
transcriber-0.0.26 spec/unit/input_path_spec.rb
transcriber-0.0.25 spec/unit/input_path_spec.rb
transcriber-0.0.24 spec/unit/input_path_spec.rb
transcriber-0.0.23 spec/unit/input_path_spec.rb
transcriber-0.0.22 spec/unit/input_path_spec.rb
transcriber-0.0.21 spec/unit/input_path_spec.rb
transcriber-0.0.20 spec/unit/input_path_spec.rb
transcriber-0.0.19 spec/unit/input_path_spec.rb
transcriber-0.0.18 spec/unit/input_path_spec.rb
transcriber-0.0.17 spec/unit/input_path_spec.rb
transcriber-0.0.16 spec/unit/input_path_spec.rb
transcriber-0.0.15 spec/unit/input_path_spec.rb
transcriber-0.0.14 spec/unit/input_path_spec.rb
transcriber-0.0.13 spec/unit/input_path_spec.rb
transcriber-0.0.12 spec/unit/input_path_spec.rb
transcriber-0.0.11 spec/unit/input_path_spec.rb
transcriber-0.0.10 spec/unit/input_path_spec.rb