Permalink
Browse files

Fixed failing specs

* Reorganized DataMapper.repository to try to use a named repository if
  a name is passed in, otherwise it will use the current repository
  in-scope, and failing that, will use a default repository.
* Some spec code was passing in arguments that were no-longer in use,
  added TODO notes so that when that area is refactored, we explicitly
  check the options to make sure only allowed ones are passed in.
*
  • Loading branch information...
1 parent 12da28d commit 2ba7b0878c5f53e70ce563b2f69fe8aeba9aa778 Dan Kubb committed Apr 20, 2008
View
@@ -82,19 +82,21 @@ def self.setup(name, uri_or_options)
# a new Session.
#
# current_repository = DataMapper.repository
- def self.repository(name = :default) # :yields: current_context
- unless block_given?
- begin
- Repository.context.last || Repository.new(name)
- #rescue NoMethodError
- # raise RepositoryNotSetupError, "#{name.inspect} repository not set up."
- end
+ def self.repository(name = nil) # :yields: current_context
+ current_repository = if name
+ Repository.new(name)
else
- begin
- return yield(Repository.context.push(Repository.new(name)))
- ensure
- Repository.context.pop
- end
+ Repository.context.last || Repository.new(Repository.default_name)
+ end
+
+ return current_repository unless block_given?
+
+ Repository.context << current_repository
+
+ begin
+ return yield(current_repository)
+ ensure
+ Repository.context.pop
end
end
-end
+end
@@ -8,6 +8,8 @@ def many_to_many(name, options = {})
raise ArgumentError, "+name+ should be a Symbol, but was #{name.class}", caller unless Symbol === name
raise ArgumentError, "+options+ should be a Hash, but was #{options.class}", caller unless Hash === options
+ # TOOD: raise an exception if unknown options are passed in
+
child_model_name = DataMapper::Inflection.demodulize(self.name)
parent_model_name = options[:class_name] || DataMapper::Inflection.classify(name)
@@ -8,6 +8,8 @@ def many_to_one(name, options = {})
raise ArgumentError, "+name+ should be a Symbol, but was #{name.class}", caller unless Symbol === name
raise ArgumentError, "+options+ should be a Hash, but was #{options.class}", caller unless Hash === options
+ # TOOD: raise an exception if unknown options are passed in
+
child_model_name = DataMapper::Inflection.demodulize(self.name)
parent_model_name = options[:class_name] || DataMapper::Inflection.classify(name)
@@ -10,6 +10,8 @@ def one_to_many(name, options = {})
raise ArgumentError, "+name+ should be a Symbol, but was #{name.class}", caller unless Symbol === name
raise ArgumentError, "+options+ should be a Hash, but was #{options.class}", caller unless Hash === options
+ # TOOD: raise an exception if unknown options are passed in
+
child_model_name = options[:class_name] || DataMapper::Inflection.classify(name)
parent_model_name = DataMapper::Inflection.demodulize(self.name)
@@ -7,6 +7,8 @@ def one_to_one(name, options = {})
raise ArgumentError, "+name+ should be a Symbol, but was #{name.class}", caller unless Symbol === name
raise ArgumentError, "+options+ should be a Hash, but was #{options.class}", caller unless Hash === options
+ # TOOD: raise an exception if unknown options are passed in
+
child_model_name = options[:class_name] || DataMapper::Inflection.classify(name)
parent_model_name = DataMapper::Inflection.demodulize(self.name)
@@ -72,7 +72,7 @@ def []=(name, value)
end
dirty_attributes << property
-
+
instance_variable_set(ivar_name, property.custom? ? property.type.dump(value, property) : property.typecast(value))
end
@@ -231,8 +231,8 @@ def default_repository_name
Repository.default_name
end
- def repository(repository_name = default_repository_name, &block)
- DataMapper.repository(repository_name, &block)
+ def repository(*args, &block)
+ DataMapper.repository(*args, &block)
end
def storage_name(repository_name = default_repository_name)
@@ -292,11 +292,11 @@ def [](key)
end
def all(options = {})
- repository(options[:repository] || default_repository_name).all(self, options)
+ repository(options[:repository]).all(self, options)
end
def first(options = {})
- repository(options[:repository] || default_repository_name).first(self, options)
+ repository(options[:repository]).first(self, options)
end
def create(values)
@@ -469,7 +469,9 @@ class Yard
property :id, Fixnum, :serial => true
property :name, String
- many_to_one :engine, :repository_name => :postgres
+ repository(:postgres) do
+ many_to_one :engine
+ end
end
@adapter.execute('CREATE SEQUENCE "yards_id_seq"')
@@ -543,7 +545,9 @@ class Host
property :id, Fixnum, :serial => true
property :name, String
- one_to_many :slices, :repository_name => :postgres
+ repository(:postgres) do |context|
+ one_to_many :slices, :test => context
+ end
end
@adapter.execute('CREATE SEQUENCE "hosts_id_seq"')
@@ -563,7 +567,9 @@ class Slice
property :id, Fixnum, :serial => true
property :name, String
- many_to_one :host, :repository_name => :postgres
+ repository(:postgres) do
+ many_to_one :host
+ end
end
@adapter.execute('CREATE SEQUENCE "slices_id_seq"')

0 comments on commit 2ba7b08

Please sign in to comment.