Created
December 7, 2011 12:55
-
-
Save FND/1442692 to your computer and use it in GitHub Desktop.
test case for apparent DataMapper bug when recursively saving associations
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Gemfile.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
source :rubygems | |
DM_VERSION = "1.2.0" | |
gem "dm-core", DM_VERSION | |
gem "dm-constraints", DM_VERSION | |
gem "dm-migrations", DM_VERSION | |
gem "dm-sqlite-adapter", DM_VERSION |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# encoding: UTF-8 | |
# test case for apparent DataMapper bug when recursively saving associations | |
require "rubygems" | |
require "dm-core" | |
require "dm-constraints" | |
require "dm-migrations" | |
# models | |
module Plan | |
class Parameter | |
include DataMapper::Resource | |
property :id, Serial | |
belongs_to :parameter, "Parameter::Base" | |
end | |
end | |
module Parameter | |
class Base | |
include DataMapper::Resource | |
property :id, Serial | |
property :type, Discriminator | |
has n, :plan_parameters, "Plan::Parameter", | |
:child_key => "parameter_id", | |
:constraint => :protect | |
end | |
class Subgrouped < Base | |
has n, :subgroups, "Parameter::Subgroup", | |
:child_key => "subgrouped_parameter_id", | |
:constraint => :destroy | |
end | |
class Subgroup | |
include DataMapper::Resource | |
property :id, Serial | |
belongs_to :subgrouped_parameter, "Parameter::Subgrouped" | |
end | |
end | |
# setup | |
#DataMapper::Logger.new($stdout, :debug) | |
DataMapper.setup(:default, "sqlite::memory:") | |
DataMapper::Model.raise_on_save_failure = true | |
DataMapper.finalize | |
DataMapper.auto_migrate! | |
# generate data | |
s = Parameter::Subgroup.new | |
p = Parameter::Subgrouped.new :subgroups => [s] | |
pp = Plan::Parameter.new :parameter => p | |
puts "[INFO] SAVING" | |
pp.save | |
puts [pp, p, s].map(&:saved?).join(" / ") | |
puts [pp, p, s].map(&:inspect) | |
puts s.subgrouped_parameter_id # nil! | |
puts s.dirty? # true => unsaved! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment