Sha256: f435c666ac4e1800eb3cb7baa2bf5dbf83218e33d2ba70084fd982b3b5d71611

Contents?: true

Size: 1.63 KB

Versions: 16

Compression:

Stored size: 1.63 KB

Contents

require File.expand_path('../../test_helper', __FILE__)

module Paid
  class PathBuilderTest < ::Test::Unit::TestCase
    class FakeClass < APIResource
      attr_reader :id
      def initialize(id); @id = id; end
      def abc; return "abc-value"; end
      def self.xyz; return "xyz-value"; end
    end

    setup do
      @params = {
        :dog => "dog-value"
      }
      @obj = FakeClass.new("fake-id")
    end

    should 'use instance methods' do
      path = "/a/:abc/123"
      expected = "/a/abc-value/123"

      actual = PathBuilder.build(path, @obj, nil)
      assert_equal(expected, actual)
    end

    should 'use instance attributes' do
      path = "/a/:id/123"
      expected = "/a/fake-id/123"
      actual = PathBuilder.build(path, @obj, nil)
      assert_equal(expected, actual)
    end

    should 'use class methods' do
      path = "/a/:xyz/123"
      expected = "/a/xyz-value/123"

      actual = PathBuilder.build(path, FakeClass, nil)
      assert_equal(expected, actual)
    end

    should 'not use class #id methods (1.8.7)' do
      path = "/a/:id/123"
      expected = "/a/param-id/123"

      actual = PathBuilder.build(path, FakeClass, { :id => "param-id" })
      assert_equal(expected, actual)
    end

    should 'use param values' do
      path = "/a/:dog/123"
      expected = "/a/dog-value/123"

      actual = PathBuilder.build(path, nil, @params)
      assert_equal(expected, actual)
    end

    should 'use both methods and params' do
      path = "/a/:dog/:abc/123"
      expected = "/a/dog-value/abc-value/123"

      actual = PathBuilder.build(path, @obj, @params)
      assert_equal(expected, actual)
    end

  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
paid-1.2.1 test/paid/path_builder_test.rb
paid-1.2.0 test/paid/path_builder_test.rb
paid-1.1.4 test/paid/path_builder_test.rb
paid-1.1.3 test/paid/path_builder_test.rb
paid-1.1.2 test/paid/path_builder_test.rb
paid-1.1.1 test/paid/path_builder_test.rb
paid-1.1.0 test/paid/path_builder_test.rb
paid-1.0.11 test/paid/path_builder_test.rb
paid-1.0.10 test/paid/path_builder_test.rb
paid-1.0.9 test/paid/path_builder_test.rb
paid-1.0.8 test/paid/path_builder_test.rb
paid-1.0.7 test/paid/path_builder_test.rb
paid-1.0.6 test/paid/path_builder_test.rb
paid-1.0.5 test/paid/path_builder_test.rb
paid-1.0.3 test/paid/path_builder_test.rb
paid-1.0.2 test/paid/path_builder_test.rb