Sha256: e619ff35dbf046b6be230501d3ea336bd6a3d6a1fa6bc0e61713e83e67983f76

Contents?: true

Size: 1.29 KB

Versions: 11

Compression:

Stored size: 1.29 KB

Contents

require 'spec_helper'

describe RestModel do
  describe '#resource' do
    before do
      class Example < RestModel
        property :login
        property :name
        property :age, type: Float
      end
    end

    it "returns a hash with properties and its values" do
      example = Example.new(login: 'jackiechan2010', name: 'Jackie Chan', age: 45)
      example.resource.should == {login: 'jackiechan2010', name: 'Jackie Chan', age: 45}
    end
  end

  context "when using not allowed names" do
    [:resource_id, :resource, :link].each do |unallowed|
      it "warns when method #{unallowed} is redefined" do
        output = out do
          eval <<-RUBY
            class Example < RestModel
              def #{unallowed}
              end
            end
          RUBY
        end
        output.should =~ /^warning: redefining '#{unallowed}' may cause serious problems/
      end

      %w(property embeds_one embeds_many has_one has_many belongs_to).each do |kind|
        it "removes method #{unallowed} created by #{kind}" do
          expect {
            eval <<-RUBY
              class Example < RestModel
                #{kind} :#{unallowed}
              end
            RUBY
          }.to raise_error "you can't define a key with name '#{unallowed}'"
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
rest_model-0.1.10 spec/unit/rest_model_spec.rb
rest_model-0.1.9 spec/unit/rest_model_spec.rb
rest_model-0.1.8 spec/unit/rest_model_spec.rb
rest_model-0.1.7 spec/unit/rest_model_spec.rb
rest_model-0.1.6 spec/unit/rest_model_spec.rb
rest_model-0.1.5 spec/unit/rest_model_spec.rb
rest_model-0.1.4 spec/unit/rest_model_spec.rb
rest_model-0.1.3 spec/unit/rest_model_spec.rb
rest_model-0.1.2 spec/unit/rest_model_spec.rb
rest_model-0.1.1 spec/unit/rest_model_spec.rb
rest_model-0.1.0 spec/unit/rest_model_spec.rb