Skip to content
This repository has been archived by the owner on Apr 17, 2018. It is now read-only.

Commit

Permalink
Pretty close...
Browse files Browse the repository at this point in the history
  • Loading branch information
sam committed May 6, 2008
1 parent 43b4f03 commit e7c88b5
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/data_mapper/resource.rb
Expand Up @@ -3,7 +3,15 @@
module DataMapper

module Resource


def self.new(default_name, &b)
x = Class.new
x.send(:include, self)
x.storage_names[:default] = default_name
x.instance_eval(&b)
x
end

@@including_classes = Set.new

# +----------------------
Expand Down
28 changes: 28 additions & 0 deletions spec/integration/resource_spec.rb
Expand Up @@ -30,6 +30,34 @@ class Orange
orange.color.should == 'orange'
end

describe "anonymity" do

before(:all) do
repository(:sqlite3) do
@planet = DataMapper::Resource.new("planets") do
property :name, String, :key => true
property :distance, Fixnum
end

@planet.auto_migrate!
end
end

it "should be able to persist" do
repository(:sqlite3) do
pluto = @planet.new
pluto.name = 'Pluto'
pluto.distance = 1_000_000
pluto.save

clone = @planet['Pluto']
clone.name.should == 'Pluto'
clone.distance.should == 1_000_000
end
end

end

describe "inheritance" do
before(:all) do
class Male
Expand Down
14 changes: 14 additions & 0 deletions spec/unit/resource_spec.rb
Expand Up @@ -292,6 +292,19 @@ class Phone
Planet.should respond_to(:exists?)
Planet.exists?.should == true
end

end

describe "anonymity" do

it "should require a default storage name and accept a block" do
pluto = DataMapper::Resource.new("planets") do
property :name, String, :key => true
end

pluto.properties[:name].should_not be_nil
end

end

describe 'when retrieving by key' do
Expand Down Expand Up @@ -346,4 +359,5 @@ class NewsPaper < Media
NewsPaper.properties.should have(2).entries
end
end

end

0 comments on commit e7c88b5

Please sign in to comment.