Sha256: 34777bd60055b6035803a4b5c1e66056b8496551017702f9205b9d5f61c8d752

Contents?: true

Size: 1.48 KB

Versions: 1

Compression:

Stored size: 1.48 KB

Contents

require 'spec_helper'
require 'integration/models/test_model'

if (HAS_SQLITE3 || HAS_MYSQL || HAS_POSTGRES)
  describe DataMapper::Predefined do
    before(:all) do
      TestModel.auto_migrate!
    end

    it "should provide the names of all predefined resources of a Model" do
      TestModel.predefined_names.should =~ [:test1, :test2]
    end

    it "should be able to define resources of a Model" do
      test1 = TestModel.test1

      test1.should_not be_nil
      test1.name.should == 'test1'
      test1.number.should == 1
      test1.optional.should == 'yo'
      test1.body.should == %{This is a test.}
    end

    it "should be able to define resources with empty attributes" do
      test2 = TestModel.test2

      test2.should_not be_nil
      test2.name.should == 'test2'
      test2.number.should == 2
      test2.optional.should == 'hello'
      test2.body.should be_nil
    end

    it "should return existing resources" do
      first_test1 = TestModel.test1
      second_test1 = TestModel.test1

      first_test1.id.should == second_test1.id
    end

    it "should provide a generic interface for accessing resources" do
      test1 = TestModel.predefined_resource(:test1)

      test1.name.should == 'test1'
      test1.number.should == 1
    end

    it "should raise an UnknownResource exception when accessing undefined resources" do
      lambda {
        TestModel.predefined_resource(:test3)
      }.should raise_error(DataMapper::Predefined::UnknownResource)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
dm-predefined-0.2.1 spec/integration/predefined_spec.rb