Skip to content

Instantly share code, notes, and snippets.

@probablykabari
Created April 7, 2011 16:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save probablykabari/908181 to your computer and use it in GitHub Desktop.
Save probablykabari/908181 to your computer and use it in GitHub Desktop.
Dynamic model creation broken in DM 1.1
require 'spec_helper'
require 'dm-core'
def create_dm_model(name)
DataMapper::Model.new(name) do
property :id, DataMapper::Property::Serial
property :name, DataMapper::Property::String
end
end
describe "Model Descendants" do
after(:each) do
DataMapper::Spec.cleanup_models
end
context "One Model" do
before(:each) do
create_dm_model("Foo")
end
it "should add a DM Model" do
Foo.should be_a_kind_of(DataMapper::Model)
end
it "should add model to descendants set" do
DataMapper::Model.descendants.should include(Foo)
end
end
context "Two Models" do
before(:each) do
create_dm_model("Foo")
create_dm_model("Bar")
end
it "should add a DM Model" do
Bar.should be_a_kind_of(DataMapper::Model)
Foo.should be_a_kind_of(DataMapper::Model)
end
it "should add model to descendants set" do
DataMapper::Model.descendants.should include(Bar)
DataMapper::Model.descendants.should include(Foo)
end
end
end
@emmanuel
Copy link

Is this still broken?

I just ran into this, and it's late so I'm posting a comment instead of checking this out for myself....

@probablykabari
Copy link
Author

Nope. It was never broken actually, it was just changed. It works the way it is done in the most recent gist.

DataMapper::Model.new(model_name)

Now the constant is set within that method, so no need for const_set, etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment