Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Initial set of heckle grade specs, not complete

  • Loading branch information...
commit a2df7e830aac73b789d8499e88ed35f3bb9d9cd4 1 parent e6f878a
Markus Schirp authored
Showing with 730 additions and 67 deletions.
  1. +21 −0 lib/mapper.rb
  2. +11 −5 lib/mapper/attribute/custom.rb
  3. +10 −0 lib/mapper/attribute/embedded.rb
  4. +7 −11 lib/mapper/attribute/object.rb
  5. +11 −18 lib/mapper/attribute_set.rb
  6. +4 −30 lib/mapper/class_methods.rb
  7. +6 −3 lib/mapper/transformer.rb
  8. +16 −0 spec/spec_helper.rb
  9. +6 −0 spec/unit/mapper/attribute/class_methods/build_spec.rb
  10. +6 −0 spec/unit/mapper/attribute/class_methods/handle_ques_spec.rb
  11. +6 −0 spec/unit/mapper/attribute/class_methods/symbol_name_spec.rb
  12. +32 −0 spec/unit/mapper/attribute/custom/add_to_dump_map_spec.rb
  13. +12 −0 spec/unit/mapper/attribute/custom/define_dumper_spec.rb
  14. +12 −0 spec/unit/mapper/attribute/custom/define_loader_spec.rb
  15. +13 −0 spec/unit/mapper/attribute/embedded/dump_spec.rb
  16. +13 −0 spec/unit/mapper/attribute/embedded/load_spec.rb
  17. +18 −0 spec/unit/mapper/attribute/embedded_collection/coerce_dump_spec.rb
  18. +18 −0 spec/unit/mapper/attribute/embedded_collection/coerce_load_spec.rb
  19. +26 −0 spec/unit/mapper/attribute/embedded_document/coerce_dump_spec.rb
  20. +25 −0 spec/unit/mapper/attribute/embedded_document/coerce_load_spec.rb
  21. +33 −0 spec/unit/mapper/attribute/object/add_to_dump_map_spec.rb
  22. +20 −0 spec/unit/mapper/attribute/object/add_to_load_map_spec.rb
  23. +30 −0 spec/unit/mapper/attribute/object/class_methods/handle_ques_spec.rb
  24. +20 −0 spec/unit/mapper/attribute/object/define_dumper_spec.rb
  25. +20 −0 spec/unit/mapper/attribute/object/define_loader_spec.rb
  26. +27 −0 spec/unit/mapper/attribute/object/dump_spec.rb
  27. +31 −0 spec/unit/mapper/attribute/object/dumper_method_source_spec.rb
  28. +27 −0 spec/unit/mapper/attribute/object/load_spec.rb
  29. +31 −0 spec/unit/mapper/attribute/object/loader_method_source_spec.rb
  30. +37 −0 spec/unit/mapper/attribute_set/add_spec.rb
  31. +11 −0 spec/unit/mapper/attribute_set/dump_names_spec.rb
  32. +39 −0 spec/unit/mapper/attribute_set/fetch_dump_name_spec.rb
  33. +11 −0 spec/unit/mapper/attribute_set/load_names_spec.rb
  34. +6 −0 spec/unit/mapper/class_methods/add_attribute_spec.rb
  35. +6 −0 spec/unit/mapper/class_methods/attribute_for_dump_name_spec.rb
  36. +6 −0 spec/unit/mapper/class_methods/attributes_spec.rb
  37. +6 −0 spec/unit/mapper/class_methods/const_missing_spec.rb
  38. +6 −0 spec/unit/mapper/class_methods/create_dumper_spec.rb
  39. +6 −0 spec/unit/mapper/class_methods/create_loader_spec.rb
  40. 0  spec/unit/mapper/class_methods/dump_names_spec.rb
  41. +6 −0 spec/unit/mapper/class_methods/dump_spec.rb
  42. +6 −0 spec/unit/mapper/class_methods/dumper_klass_spec.rb
  43. +6 −0 spec/unit/mapper/class_methods/instanciate_model_spec.rb
  44. +6 −0 spec/unit/mapper/class_methods/load_names_spec.rb
  45. +6 −0 spec/unit/mapper/class_methods/load_spec.rb
  46. +6 −0 spec/unit/mapper/class_methods/loader_klass_spec.rb
  47. +6 −0 spec/unit/mapper/class_methods/map_spec.rb
  48. +6 −0 spec/unit/mapper/class_methods/model_spec.rb
  49. +6 −0 spec/unit/mapper/class_methods/read_model_spec.rb
  50. +6 −0 spec/unit/mapper/class_methods/set_mapper_spec.rb
  51. +6 −0 spec/unit/mapper/transformer/class_methods/transfer_spec.rb
  52. +6 −0 spec/unit/mapper/transformer/dumper/class_methods/dump_spec.rb
  53. +6 −0 spec/unit/mapper/transformer/dumper/object_spec.rb
  54. +6 −0 spec/unit/mapper/transformer/loader/class_methods/load_spec.rb
View
21 lib/mapper.rb
@@ -6,6 +6,27 @@ module Mapper
def self.included(descendant)
descendant.extend(ClassMethods)
+ create_dumper(descendant)
+ create_loader(descendant)
+ end
+
+private
+
+ def self.create_dumper(descendant)
+ klass = Class.new(Transformer::Dumper)
+ set_mapper(klass,descendant)
+ klass.instance_variable_set(:@mapper,descendant)
+ descendant.const_set(:Dumper,klass)
+ end
+
+ def self.create_loader(descendant)
+ klass = Class.new(Transformer::Loader)
+ set_mapper(klass,descendant)
+ descendant.const_set(:Loader,klass)
+ end
+
+ def self.set_mapper(klass,mapper)
+ klass.instance_variable_set(:@mapper,mapper)
end
end
View
16 lib/mapper/attribute/custom.rb
@@ -3,21 +3,27 @@ module Mapper
class Attribute
# A mapper attribute with custom behaviour
class Custom < Object
- def initialize(name,options)
- @load_name = name
- @dump_names = Array(options.fetch(:to,name))
- end
-
def add_to_dump_map(dump_map)
@dump_names.each do |name|
dump_map[name]=self
end
+
+ self
end
def define_loader(klass)
+ self
end
def define_dumper(klass)
+ self
+ end
+
+ private
+
+ def initialize(name,options={})
+ @load_name = name
+ @dump_names = Array(options.fetch(:to,name))
end
end
end
View
10 lib/mapper/attribute/embedded.rb
@@ -14,6 +14,16 @@ def dump(instance)
def load(dump)
coerce_load(super)
end
+
+ private
+
+ def coerce_dump(value)
+ raise NotImplementedError,"#{self.class.inspect}#coerce_dump must be implemented"
+ end
+
+ def coerce_load(value)
+ raise NotImplementedError,"#{self.class.inspect}#coerce_load must be implemented"
+ end
end
end
end
View
18 lib/mapper/attribute/object.rb
@@ -12,13 +12,17 @@ def self.handle?(class_or_name)
def add_to_dump_map(dump_map)
dump_map[@dump_name]=self
+
+ self
end
def add_to_load_map(load_map)
load_map[@load_name]=self
+
+ self
end
- def initialize(load_name,options)
+ def initialize(load_name,options={})
@load_name = load_name
@dump_name = options.fetch(:to,load_name)
end
@@ -47,20 +51,12 @@ def #{@dump_name}
RUBY
end
- def dump_value(object)
+ def dump(object)
object.send(@load_name)
end
- def load_value(dump)
- dump.fetch(@dump_name)
- end
-
- def dump(instance)
- dump_value(instance)
- end
-
def load(dump)
- load_value(dump)
+ dump.fetch(@dump_name)
end
end
end
View
29 lib/mapper/attribute_set.rb
@@ -12,14 +12,6 @@ def add(attribute)
self
end
- def dump_map
- @dump_map ||= collect(:add_to_dump_map)
- end
-
- def load_map
- @load_map ||= collect(:add_to_load_map)
- end
-
def dump_names
dump_map.keys
end
@@ -27,19 +19,21 @@ def dump_names
def load_names
load_map.keys
end
-
- def load_name(name,dump)
- fetch(name).load(dump)
- end
-
- def dump_name(name,object)
- fetch(name).dump(object)
+
+ def fetch_dump_name(name)
+ dump_map.fetch(name) do
+ raise ArgumentError,"no attribute with dump name of #{name.inspect} does exist"
+ end
end
private
- def fetch(name)
- dump_map.fetch(name)
+ def dump_map
+ @dump_map ||= collect(:add_to_dump_map)
+ end
+
+ def load_map
+ @load_map ||= collect(:add_to_load_map)
end
def collect(method)
@@ -48,7 +42,6 @@ def collect(method)
end
end
-
def reset
@dump_map = @load_map = nil
self
View
34 lib/mapper/class_methods.rb
@@ -1,40 +1,14 @@
module Mapper
module ClassMethods
- def self.extended(descendant)
- super
- create_dumper(descendant)
- create_loader(descendant)
- end
-
- def self.create_dumper(descendant)
- klass = Class.new(Transformer::Dumper)
- set_mapper(klass,descendant)
- klass.instance_variable_set(:@mapper,descendant)
- descendant.const_set(:Dumper,klass)
- end
-
- def self.create_loader(descendant)
- klass = Class.new(Transformer::Loader)
- set_mapper(klass,descendant)
- descendant.const_set(:Loader,klass)
- end
-
- def self.set_mapper(klass,mapper)
- klass.instance_variable_set(:@mapper,mapper)
- end
-
- def load_name(name,object)
- attributes.load_name(name,object)
- end
-
- def dump_name(name,object)
- attributes.dump_name(name,object)
- end
def dump_names
attributes.dump_names
end
+ def attribute_for_dump_name(name)
+ attributes.fetch_dump_name(name)
+ end
+
def load_names
attributes.load_names
end
View
9 lib/mapper/transformer.rb
@@ -11,7 +11,6 @@ def self.transfer(names,transformator)
end
end
-
private
def mapper
@@ -25,6 +24,10 @@ def memonize(name)
end
end
+ def attribute(name)
+ mapper.attribute_for_dump_name(name)
+ end
+
# Loader base class
class Loader < Transformer
def initialize(dump)
@@ -36,7 +39,7 @@ def initialize(dump)
def load(name)
memonize(name) do
- mapper.load_name(name,@dump)
+ attribute(name).load(@dump)
end
end
@@ -63,7 +66,7 @@ def initialize(object)
def dump(name)
memonize(name) do
- mapper.dump_name(name,@object)
+ attribute(name).dump(@object)
end
end
View
16 spec/spec_helper.rb
@@ -9,4 +9,20 @@
Dir.glob('spec/**/*_shared.rb').each { |file| require File.expand_path(file) }
+
+module SpecHelper
+ def compress_prefix(lines)
+ lines = lines.split("\n")
+ match = lines.first.match(/^[ ]*/)
+ length = match.to_s.length
+ lines.map do |line|
+ line[length..-1]
+ end.join("\n")
+ end
+end
+
+RSpec.configure do |config|
+ config.include SpecHelper
+end
+
require 'mapper'
View
6 spec/unit/mapper/attribute/class_methods/build_spec.rb
@@ -0,0 +1,6 @@
+require 'spec_helper'
+
+describe Mapper::Attribute,'.build' do
+ it 'should' do
+ end
+end
View
6 spec/unit/mapper/attribute/class_methods/handle_ques_spec.rb
@@ -0,0 +1,6 @@
+require 'spec_helper'
+
+describe Mapper::Attribute,'.build' do
+ it 'should' do
+ end
+end
View
6 spec/unit/mapper/attribute/class_methods/symbol_name_spec.rb
@@ -0,0 +1,6 @@
+require 'spec_helper'
+
+describe Mapper::Attribute,'.build' do
+ it 'should' do
+ end
+end
View
32 spec/unit/mapper/attribute/custom/add_to_dump_map_spec.rb
@@ -0,0 +1,32 @@
+require 'spec_helper'
+
+describe Mapper::Attribute::Custom,'#add_to_dump_map' do
+ let(:object) { described_class.new(:name,options) }
+ let(:options) { {} }
+ let(:dump_map) { {} }
+
+ subject { object.add_to_dump_map(dump_map) }
+
+ context 'with default options' do
+ it 'should add dump_name to dump map' do
+ subject
+ dump_map.should == { :name => object }
+ end
+
+ it 'should return self' do
+ should be(object)
+ end
+ end
+
+ context 'when dumping to many fields' do
+ let(:options) { { :to => [:a,:b] } }
+ it 'should add all fields to dump map' do
+ subject
+ dump_map.should == { :a => object, :b => object }
+ end
+
+ it 'should return self' do
+ should be(object)
+ end
+ end
+end
View
12 spec/unit/mapper/attribute/custom/define_dumper_spec.rb
@@ -0,0 +1,12 @@
+require 'spec_helper'
+
+describe Mapper::Attribute::Custom,'#define_dumper' do
+ let(:object) { described_class.new(:name) }
+ let(:dumper_klass) { Class.new.freeze }
+
+ subject { object.define_dumper(dumper_klass) }
+
+ it 'should not modify dumper klass' do
+ subject
+ end
+end
View
12 spec/unit/mapper/attribute/custom/define_loader_spec.rb
@@ -0,0 +1,12 @@
+require 'spec_helper'
+
+describe Mapper::Attribute::Custom,'#define_loader' do
+ let(:object) { described_class.new(:name) }
+ let(:loader_klass) { Class.new.freeze }
+
+ subject { object.define_loader(loader_klass) }
+
+ it 'should not modify loader klass' do
+ subject
+ end
+end
View
13 spec/unit/mapper/attribute/embedded/dump_spec.rb
@@ -0,0 +1,13 @@
+require 'spec_helper'
+
+describe Mapper::Attribute::Embedded,'#dump' do
+ let(:object) { described_class.new(:name,:mapper => mapper) }
+ let(:mapper) { mock }
+ let(:value) { mock(:name => mock) }
+
+ subject { object.dump(value) }
+
+ it 'should raise not implemented error' do
+ expect { subject }.to raise_error(NotImplementedError,"#{described_class.inspect}#coerce_dump must be implemented")
+ end
+end
View
13 spec/unit/mapper/attribute/embedded/load_spec.rb
@@ -0,0 +1,13 @@
+require 'spec_helper'
+
+describe Mapper::Attribute::Embedded,'#load' do
+ let(:object) { described_class.new(:name,:mapper => mapper) }
+ let(:mapper) { mock }
+ let(:value) { { :name => mock } }
+
+ subject { object.load(value) }
+
+ it 'should raise not implemented error' do
+ expect { subject }.to raise_error(NotImplementedError,"#{described_class.inspect}#coerce_load must be implemented")
+ end
+end
View
18 spec/unit/mapper/attribute/embedded_collection/coerce_dump_spec.rb
@@ -0,0 +1,18 @@
+require 'spec_helper'
+
+describe Mapper::Attribute::EmbeddedCollection,'#coerce_dump' do
+ let(:object) { described_class.new(:name,:mapper => mapper) }
+ let(:mapper) { Mapper::Attribute::Object.new(:other_name) }
+
+ subject { object.coerce_dump(value) }
+
+ let(:item) { mock }
+ let(:coerced) { mock }
+
+ let(:value) { [item] }
+
+ it 'should delegate each value to inner mapper' do
+ mapper.should_receive(:dump).with(item).and_return(coerced)
+ subject.should == [coerced]
+ end
+end
View
18 spec/unit/mapper/attribute/embedded_collection/coerce_load_spec.rb
@@ -0,0 +1,18 @@
+require 'spec_helper'
+
+describe Mapper::Attribute::EmbeddedCollection,'#coerce_load' do
+ let(:object) { described_class.new(:name,:mapper => mapper) }
+ let(:mapper) { Mapper::Attribute::Object.new(:other_name) }
+
+ subject { object.coerce_load(value) }
+
+ let(:item) { mock }
+ let(:coerced) { mock }
+
+ let(:value) { [item] }
+
+ it 'should delegate each value to inner mapper' do
+ mapper.should_receive(:load).with(item).and_return(coerced)
+ subject.should == [coerced]
+ end
+end
View
26 spec/unit/mapper/attribute/embedded_document/coerce_dump_spec.rb
@@ -0,0 +1,26 @@
+require 'spec_helper'
+
+describe Mapper::Attribute::EmbeddedDocument,'#coerce_dump' do
+ let(:object) { described_class.new(:name,:mapper => mapper) }
+ let(:mapper) { Mapper::Attribute::Object.new(:other_name) }
+
+ subject { object.coerce_dump(value) }
+
+ let(:coerced) { mock }
+
+ let(:value) { mock }
+
+ context 'when value is NOT nil' do
+ it 'should delegate each value to inner mapper' do
+ mapper.should_receive(:dump).with(value).and_return(coerced)
+ subject.should be(coerced)
+ end
+ end
+
+ context 'when value is nil' do
+ let(:value) { nil }
+ it 'should return nil' do
+ should be_nil
+ end
+ end
+end
View
25 spec/unit/mapper/attribute/embedded_document/coerce_load_spec.rb
@@ -0,0 +1,25 @@
+require 'spec_helper'
+
+describe Mapper::Attribute::EmbeddedDocument,'#coerce_load' do
+ let(:object) { described_class.new(:name,:mapper => mapper) }
+ let(:mapper) { Mapper::Attribute::Object.new(:other_name) }
+
+ subject { object.coerce_load(value) }
+
+ let(:coerced) { mock }
+ let(:value) { mock }
+
+ context 'when value is NOT nil' do
+ it 'should delegate each value to inner mapper' do
+ mapper.should_receive(:load).with(value).and_return(coerced)
+ subject.should be(coerced)
+ end
+ end
+
+ context 'when value is nil' do
+ let(:value) { nil }
+ it 'should return nil' do
+ should be_nil
+ end
+ end
+end
View
33 spec/unit/mapper/attribute/object/add_to_dump_map_spec.rb
@@ -0,0 +1,33 @@
+require 'spec_helper'
+
+describe Mapper::Attribute::Object,'#add_to_dump_map' do
+ let(:object) { described_class.new(:name,options) }
+ let(:options) { {} }
+ let(:dump_map) { {} }
+
+ subject { object.add_to_dump_map(dump_map) }
+
+ context 'with default options' do
+ it 'should add dump_name to dump map' do
+ subject
+ dump_map.should == { :name => object }
+ end
+
+ it 'should return self' do
+ should be(object)
+ end
+ end
+
+ context 'with aliasing dump' do
+ let(:options) { { :to => :other } }
+
+ it 'should add dump_name to dump map' do
+ subject
+ dump_map.should == { :other => object }
+ end
+
+ it 'should return self' do
+ should be(object)
+ end
+ end
+end
View
20 spec/unit/mapper/attribute/object/add_to_load_map_spec.rb
@@ -0,0 +1,20 @@
+require 'spec_helper'
+
+describe Mapper::Attribute::Object,'#add_to_load_map' do
+ let(:object) { described_class.new(:name,options) }
+ let(:options) { {} }
+ let(:load_map) { {} }
+
+ subject { object.add_to_load_map(load_map) }
+
+ context 'with default options' do
+ it 'should add load_name to load map' do
+ subject
+ load_map.should == { :name => object }
+ end
+
+ it 'should return self' do
+ should be(object)
+ end
+ end
+end
View
30 spec/unit/mapper/attribute/object/class_methods/handle_ques_spec.rb
@@ -0,0 +1,30 @@
+require 'spec_helper'
+
+describe Mapper::Attribute::Object,'.handle?' do
+ let(:object) { described_class }
+
+ subject { object.handle?(class_or_name) }
+
+ context 'with ::Object' do
+ let(:class_or_name) { ::Object }
+ it { should be_true }
+ end
+
+ context 'with :Object' do
+ let(:class_or_name) { :Object }
+ it { should be_true }
+ end
+
+ context 'with Mapper::Attribute::Object' do
+ let(:class_or_name) { Mapper::Attribute::Object }
+ it { should be_true }
+ end
+
+ context 'with anything elase' do
+ it 'should be false' do
+ [Mapper,Object.new,Mapper::Attribute::EmbeddedDocument].each do |input|
+ object.handle?(input).should be_false
+ end
+ end
+ end
+end
View
20 spec/unit/mapper/attribute/object/define_dumper_spec.rb
@@ -0,0 +1,20 @@
+require 'spec_helper'
+
+describe Mapper::Attribute::Object,'#define_dumper' do
+ let(:object) { described_class.new(name,options) }
+
+ let(:name) { :name }
+ let(:options) { {} }
+
+ let(:dumper_klass) { mock }
+
+ subject { object.define_dumper(dumper_klass) }
+
+ it 'should define method on dumper klass with correct ruby' do
+ dumper_klass.
+ should_receive(:class_eval).
+ with(object.dumper_method_source,"/home/mbj/devel/mapper/lib/mapper/attribute/object.rb",44)
+
+ subject
+ end
+end
View
20 spec/unit/mapper/attribute/object/define_loader_spec.rb
@@ -0,0 +1,20 @@
+require 'spec_helper'
+
+describe Mapper::Attribute::Object,'#define_loader' do
+ let(:object) { described_class.new(name,options) }
+
+ let(:name) { :name }
+ let(:options) { {} }
+
+ let(:dumper_klass) { mock }
+
+ subject { object.define_loader(dumper_klass) }
+
+ it 'should define method on dumper klass with correct ruby' do
+ dumper_klass.
+ should_receive(:class_eval).
+ with(object.loader_method_source,"/home/mbj/devel/mapper/lib/mapper/attribute/object.rb",31)
+
+ subject
+ end
+end
View
27 spec/unit/mapper/attribute/object/dump_spec.rb
@@ -0,0 +1,27 @@
+require 'spec_helper'
+
+describe Mapper::Attribute::Object,'#dump' do
+ let(:object) { described_class.new(name,options) }
+
+ let(:name) { :name }
+ let(:options) { {} }
+
+ let(:value) { mock }
+ let(:domain_object) { mock(:name => value) }
+
+ subject { object.dump(domain_object) }
+
+ context 'with defaults' do
+ it 'should load value' do
+ should be(value)
+ end
+ end
+
+ context 'with aliased dump name' do
+ let(:options) { { :to => :other } }
+
+ it 'should load value' do
+ should be(value)
+ end
+ end
+end
View
31 spec/unit/mapper/attribute/object/dumper_method_source_spec.rb
@@ -0,0 +1,31 @@
+require 'spec_helper'
+
+describe Mapper::Attribute::Object,'#dumper_method_source' do
+ let(:object) { described_class.new(name,options) }
+
+ let(:name) { :name }
+ let(:options) { {} }
+
+ subject { object.dumper_method_source }
+
+ context 'with defaults' do
+ it 'should create correct ruby' do
+ compress_prefix(subject).should == compress_prefix(<<-RUBY)
+ def name
+ dump(:name)
+ end
+ RUBY
+ end
+ end
+
+ context 'with aliased dump name' do
+ let(:options) { { :to => :other } }
+ it 'should create correct ruby' do
+ compress_prefix(subject).should == compress_prefix(<<-RUBY)
+ def other
+ dump(:other)
+ end
+ RUBY
+ end
+ end
+end
View
27 spec/unit/mapper/attribute/object/load_spec.rb
@@ -0,0 +1,27 @@
+require 'spec_helper'
+
+describe Mapper::Attribute::Object,'#load' do
+ let(:object) { described_class.new(name,options) }
+
+ let(:name) { :name }
+ let(:options) { {} }
+
+ let(:value) { mock }
+ let(:dump) { { :name => value } }
+
+ subject { object.load(dump) }
+
+ context 'with defaults' do
+ it 'should load value' do
+ should be(value)
+ end
+ end
+
+ context 'with aliased dump name' do
+ let(:options) { { :to => :other } }
+ let(:dump) { { :other => value } }
+ it 'should load value' do
+ should be(value)
+ end
+ end
+end
View
31 spec/unit/mapper/attribute/object/loader_method_source_spec.rb
@@ -0,0 +1,31 @@
+require 'spec_helper'
+
+describe Mapper::Attribute::Object,'#loader_method_source' do
+ let(:object) { described_class.new(name,options) }
+
+ let(:name) { :name }
+ let(:options) { {} }
+
+ subject { object.loader_method_source }
+
+ context 'with defaults' do
+ it 'should create correct ruby' do
+ compress_prefix(subject).should == compress_prefix(<<-RUBY)
+ def name
+ load(:name)
+ end
+ RUBY
+ end
+ end
+
+ context 'with aliased dump name' do
+ let(:options) { { :to => :other } }
+ it 'should create correct ruby' do
+ compress_prefix(subject).should == compress_prefix(<<-RUBY)
+ def name
+ load(:other)
+ end
+ RUBY
+ end
+ end
+end
View
37 spec/unit/mapper/attribute_set/add_spec.rb
@@ -0,0 +1,37 @@
+require 'spec_helper'
+
+describe Mapper::AttributeSet,'#add' do
+ let(:object) { described_class.new }
+ let(:attribute) { Mapper::Attribute::Object.new(:load_name,:to => :dump_name) }
+
+ subject { object.add(attribute) }
+
+ it 'should add attribute to load names' do
+ subject
+ object.load_names.should == [:load_name]
+ end
+
+ it 'should add attribute to dump names' do
+ subject
+ object.dump_names.should == [:dump_name]
+ end
+
+ context 'when attribute set is not empty' do
+ before do
+ object.add(Mapper::Attribute::Object.new(:something))
+ # make sure we have a cache
+ object.load_names
+ object.dump_names
+ end
+
+ it 'should add attribute to load names' do
+ subject
+ object.load_names.to_set.should == [:something,:load_name].to_set
+ end
+
+ it 'should add attribute to dump names' do
+ subject
+ object.dump_names.to_set.should == [:something,:dump_name].to_set
+ end
+ end
+end
View
11 spec/unit/mapper/attribute_set/dump_names_spec.rb
@@ -0,0 +1,11 @@
+require 'spec_helper'
+
+describe Mapper::AttributeSet,'#dump_names' do
+ let(:object) { described_class.new }
+
+ subject { object.dump_names }
+
+ context 'when empty' do
+ it { should be_empty }
+ end
+end
View
39 spec/unit/mapper/attribute_set/fetch_dump_name_spec.rb
@@ -0,0 +1,39 @@
+require 'spec_helper'
+
+describe Mapper::AttributeSet,'#fetch_dump_name' do
+ let(:object) { described_class.new }
+
+ subject { object.fetch_dump_name(dump_name) }
+
+ let(:attribute) do
+ Object.new.extend(Module.new do
+ def add_to_load_map(load_map)
+ load_map[:load_name]=self
+ end
+
+ def add_to_dump_map(dump_map)
+ dump_map[:dump_name]=self
+ end
+ end)
+ end
+
+ before do
+ object.add(attribute)
+ end
+
+ context 'when dump name exists' do
+ let(:dump_name) { :dump_name }
+
+ it 'should return attribute' do
+ should be(attribute)
+ end
+ end
+
+ context 'when dump name does NOT exist' do
+ let(:dump_name) { :unexistend }
+
+ it 'should raise ArgumentError' do
+ expect { subject }.to raise_error(ArgumentError,"no attribute with dump name of :unexistend does exist")
+ end
+ end
+end
View
11 spec/unit/mapper/attribute_set/load_names_spec.rb
@@ -0,0 +1,11 @@
+require 'spec_helper'
+
+describe Mapper::AttributeSet,'#load_names' do
+ let(:object) { described_class.new }
+
+ subject { object.load_names }
+
+ context 'when empty' do
+ it { should be_empty }
+ end
+end
View
6 spec/unit/mapper/class_methods/add_attribute_spec.rb
@@ -0,0 +1,6 @@
+require 'spec_helper'
+
+describe Mapper::ClassMethods,'#add_attribute' do
+ it 'should' do
+ end
+end
View
6 spec/unit/mapper/class_methods/attribute_for_dump_name_spec.rb
@@ -0,0 +1,6 @@
+require 'spec_helper'
+
+describe Mapper::ClassMethods,'#attribute_for_dump_name' do
+ it 'should' do
+ end
+end
View
6 spec/unit/mapper/class_methods/attributes_spec.rb
@@ -0,0 +1,6 @@
+require 'spec_helper'
+
+describe Mapper::ClassMethods,'#attributes' do
+ it 'should' do
+ end
+end
View
6 spec/unit/mapper/class_methods/const_missing_spec.rb
@@ -0,0 +1,6 @@
+require 'spec_helper'
+
+describe Mapper::ClassMethods,'#attributes' do
+ it 'should' do
+ end
+end
View
6 spec/unit/mapper/class_methods/create_dumper_spec.rb
@@ -0,0 +1,6 @@
+require 'spec_helper'
+
+describe Mapper::ClassMethods,'#create_dumper' do
+ it 'should' do
+ end
+end
View
6 spec/unit/mapper/class_methods/create_loader_spec.rb
@@ -0,0 +1,6 @@
+require 'spec_helper'
+
+describe Mapper::ClassMethods,'#create_loader' do
+ it 'should' do
+ end
+end
View
0  spec/unit/mapper/class_methods/dump_names_spec.rb
No changes.
View
6 spec/unit/mapper/class_methods/dump_spec.rb
@@ -0,0 +1,6 @@
+require 'spec_helper'
+
+describe Mapper::ClassMethods,'#dump' do
+ it 'should' do
+ end
+end
View
6 spec/unit/mapper/class_methods/dumper_klass_spec.rb
@@ -0,0 +1,6 @@
+require 'spec_helper'
+
+describe Mapper::ClassMethods,'#dumper_klass' do
+ it 'should' do
+ end
+end
View
6 spec/unit/mapper/class_methods/instanciate_model_spec.rb
@@ -0,0 +1,6 @@
+require 'spec_helper'
+
+describe Mapper::ClassMethods,'#instanciat_model' do
+ it 'should' do
+ end
+end
View
6 spec/unit/mapper/class_methods/load_names_spec.rb
@@ -0,0 +1,6 @@
+require 'spec_helper'
+
+describe Mapper::ClassMethods,'#load_names' do
+ it 'should' do
+ end
+end
View
6 spec/unit/mapper/class_methods/load_spec.rb
@@ -0,0 +1,6 @@
+require 'spec_helper'
+
+describe Mapper::ClassMethods,'#load' do
+ it 'should' do
+ end
+end
View
6 spec/unit/mapper/class_methods/loader_klass_spec.rb
@@ -0,0 +1,6 @@
+require 'spec_helper'
+
+describe Mapper::ClassMethods,'#loader_klass' do
+ it 'should' do
+ end
+end
View
6 spec/unit/mapper/class_methods/map_spec.rb
@@ -0,0 +1,6 @@
+require 'spec_helper'
+
+describe Mapper::ClassMethods,'#map' do
+ it 'should' do
+ end
+end
View
6 spec/unit/mapper/class_methods/model_spec.rb
@@ -0,0 +1,6 @@
+require 'spec_helper'
+
+describe Mapper::ClassMethods,'#model' do
+ it 'should' do
+ end
+end
View
6 spec/unit/mapper/class_methods/read_model_spec.rb
@@ -0,0 +1,6 @@
+require 'spec_helper'
+
+describe Mapper::ClassMethods,'#read_model' do
+ it 'should' do
+ end
+end
View
6 spec/unit/mapper/class_methods/set_mapper_spec.rb
@@ -0,0 +1,6 @@
+require 'spec_helper'
+
+describe Mapper::ClassMethods,'#set_mapper' do
+ it 'should' do
+ end
+end
View
6 spec/unit/mapper/transformer/class_methods/transfer_spec.rb
@@ -0,0 +1,6 @@
+require 'spec_helper'
+
+describe Mapper::Transformer,'.transfer' do
+ it 'should' do
+ end
+end
View
6 spec/unit/mapper/transformer/dumper/class_methods/dump_spec.rb
@@ -0,0 +1,6 @@
+require 'spec_helper'
+
+describe Mapper::Attribute,'.build' do
+ it 'should' do
+ end
+end
View
6 spec/unit/mapper/transformer/dumper/object_spec.rb
@@ -0,0 +1,6 @@
+require 'spec_helper'
+
+describe Mapper::Transformer::Dumper,'#object' do
+ it 'should' do
+ end
+end
View
6 spec/unit/mapper/transformer/loader/class_methods/load_spec.rb
@@ -0,0 +1,6 @@
+require 'spec_helper'
+
+describe Mapper::Transformer::Loader,'.load' do
+ it 'should' do
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.