superdupe 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -7,4 +7,40 @@ SuperDupe provides two things:
7
7
  SuperDupe is a fork of the originally gem dupe 0.5.1 (Matt Parker). At first, the gem try to use only the available mocked resources. If you have the requirement to send external requests without mocking, take an extra parameter for this situation.
8
8
 
9
9
  # Install the gem
10
- gem install superdupe
10
+ gem install superdupe
11
+
12
+ # Usage
13
+ *Implemented ActiveResource class*
14
+ class Customer < ActiveResource::Base
15
+ self.site = ''
16
+ end
17
+
18
+ *Register a mock response*
19
+ Dupe.create <class_name>, <attributes>
20
+ Dupe.create Customer, :name => 'test customer'
21
+
22
+ *Find a registered object*
23
+ Customer.find 1
24
+
25
+ *Find all registered objects*
26
+ Customer.find :all
27
+
28
+ *Find registered url patterns*
29
+ Dupe.network.mocks[<http-method>]
30
+ Dupe.network.mocks[:get]
31
+
32
+ *Reset registered url patterns*
33
+ Dupe.reset
34
+
35
+ *Register a custom mock with a param-filter*
36
+ Get %r{\/customers\.xml\?state=(active|inactive)} do |state|
37
+ if state == 'active'
38
+ Dupe.find(:"Customers") {|c| c.state == 'active'}
39
+ else
40
+ Dupe.find(:"Customers") {|c| c.state == 'inactive'}
41
+ end
42
+ end
43
+ # Register a custom mock with the entered url pattern
44
+
45
+ *Find the custom registered object*
46
+ Customer.find :all, :params => {:state => 'active'}
@@ -15,8 +15,9 @@ module ActiveResource #:nodoc:
15
15
  # Overwrite the configuration of ActiveResource authentication (self.password). Don't need it for mocking.
16
16
  def password=(password)
17
17
  end
18
+
18
19
 
19
- def find(*arguments)
20
+ def find(*arguments)
20
21
  scope = arguments.slice!(0)
21
22
  options = arguments.slice!(0) || {}
22
23
 
@@ -168,33 +168,35 @@ class Dupe
168
168
  model_object.tap do |m|
169
169
  models[model_name] = m
170
170
  database.create_table model_name
171
+
171
172
  mocks = %{
172
173
  network.define_service_mock(
173
174
  :get,
174
- %r{^#{model_name.to_s.titleize.constantize.prefix rescue '/'}#{model_name.to_s.pluralize}\\.xml$},
175
- proc { Dupe.find(:#{model_name.to_s.pluralize}) }
175
+ %r{^#{model_name.to_s.constantize.prefix rescue '/'}#{model_name.to_s.demodulize.downcase.pluralize}\\.xml$},
176
+ proc { Dupe.find(:"#{model_name.to_s.pluralize}") }
176
177
  )
177
178
  network.define_service_mock(
178
179
  :get,
179
- %r{^#{model_name.to_s.titleize.constantize.prefix rescue '/'}#{model_name.to_s.pluralize}/(\\d+)\\.xml$},
180
- proc {|id| Dupe.find(:#{model_name}) {|resource| resource.id == id.to_i}}
180
+ %r{^#{model_name.to_s.constantize.prefix rescue '/'}#{model_name.to_s.demodulize.downcase.pluralize}/(\\d+)\\.xml$},
181
+ proc {|id| Dupe.find(:"#{model_name.to_s}") {|resource| resource.id == id.to_i}}
181
182
  )
182
183
  network.define_service_mock(
183
184
  :post,
184
- %r{^#{model_name.to_s.titleize.constantize.prefix rescue '/'}#{model_name.to_s.pluralize}\\.xml$},
185
- proc { |post_body| Dupe.create(:#{model_name.to_s}, post_body) }
185
+ %r{^#{model_name.to_s.constantize.prefix rescue '/'}#{model_name.to_s.demodulize.downcase.pluralize}\\.xml$},
186
+ proc { |post_body| Dupe.create(:"#{model_name.to_s}", post_body) }
186
187
  )
187
188
  network.define_service_mock(
188
189
  :put,
189
- %r{^#{model_name.to_s.titleize.constantize.prefix rescue '/'}#{model_name.to_s.pluralize}/(\\d+)\\.xml$},
190
- proc { |id, put_data| Dupe.find(:#{model_name.to_s}) {|resource| resource.id == id.to_i}.merge!(put_data) }
190
+ %r{^#{model_name.to_s.constantize.prefix rescue '/'}#{model_name.to_s.demodulize.downcase.pluralize}/(\\d+)\\.xml$},
191
+ proc { |id, put_data| Dupe.find(:"#{model_name.to_s}") {|resource| resource.id == id.to_i}.merge!(put_data) }
191
192
  )
192
193
  network.define_service_mock(
193
194
  :delete,
194
- %r{^#{model_name.to_s.titleize.constantize.prefix rescue '/'}#{model_name.to_s.pluralize}/(\\d+)\\.xml$},
195
- proc { |id| Dupe.delete(:#{model_name.to_s}) {|resource| resource.id == id.to_i} }
195
+ %r{^#{model_name.to_s.constantize.prefix rescue '/'}#{model_name.to_s.demodulize.downcase.pluralize}/(\\d+)\\.xml$},
196
+ proc { |id| Dupe.delete(:"#{model_name.to_s}") {|resource| resource.id == id.to_i} }
196
197
  )
197
198
  }
199
+
198
200
  eval(mocks)
199
201
  end
200
202
  end
@@ -260,7 +262,7 @@ class Dupe
260
262
  def create(model_name, records={})
261
263
  model_name = model_name.to_s.singularize.to_sym
262
264
  define model_name unless model_exists(model_name)
263
- records = records.kind_of?(Array) ? records.map {|r| r.symbolize_keys} : records.symbolize_keys!
265
+ records = records.kind_of?(Array) ? records.map {|r| r.symbolize_keys} : records.symbolize_keys!
264
266
  create_and_insert records, :into => model_name
265
267
  end
266
268
 
@@ -488,14 +490,13 @@ class Dupe
488
490
  ) if !into || !into.kind_of?(Hash) || !into[:into]
489
491
 
490
492
  # do we have several records to create, and are they each a hash?
491
- if records.kind_of?(Array) and
492
- records.inject(true) {|bool, r| bool and r.kind_of?(Hash)}
493
+ if records.kind_of?(Array) and records.inject(true) {|bool, r| bool and r.kind_of?(Hash)}
493
494
  [].tap do |results|
494
495
  records.each do |record|
495
496
  results << models[into[:into]].create(record).tap {|r| database.insert r}
496
497
  end
497
498
  end
498
-
499
+
499
500
  # do we only have one record to create, and is it a hash?
500
501
  elsif records.kind_of?(Hash)
501
502
  models[into[:into]].create(records).tap {|r| database.insert r}
@@ -25,7 +25,6 @@ class Dupe
25
25
  StandardError,
26
26
  "Tried to mock a response to a non-matched url! This should never occur. My pattern: #{@url_pattern}. Url: #{url}"
27
27
  ) unless match?(url)
28
-
29
28
  grouped_results = url_pattern.match(url)[1..-1]
30
29
  grouped_results << body if body
31
30
  resp = @response.call *grouped_results
@@ -49,7 +48,12 @@ class Dupe
49
48
  raise ResourceNotFoundError, "Failed with 404: the request '#{url}' returned nil."
50
49
 
51
50
  when Dupe::Database::Record
52
- resp = resp.to_xml_safe(:root => resp.__model__.name.to_s)
51
+ # if a namespace is available, demodulize the modelname
52
+ if resp.__model__.name.to_s.include?('::')
53
+ resp = resp.to_xml_safe(:root => resp.__model__.name.to_s.demodulize)
54
+ else
55
+ resp = resp.to_xml_safe(:root => resp.__model__.name.to_s)
56
+ end
53
57
 
54
58
  when Array
55
59
  if resp.empty?
@@ -21,7 +21,13 @@ class Dupe
21
21
  end
22
22
 
23
23
  def record_inspect
24
- class_name = __model__ ? "Duped::#{__model__.name.to_s.titleize}" : self.class.to_s
24
+ # if a namespace is available, the titleize method destroy the scope operator
25
+ if class_name = __model__
26
+ __model__name.to_s.include?('::') ? "Duped::#{__model__.name.to_s}" : "Duped::#{__model__.name.to_s.titleize}"
27
+ else
28
+ self.class.to_s
29
+ end
30
+
25
31
  "<##{class_name}".tap do |inspection|
26
32
  keys.each do |key|
27
33
  inspection << " #{key}=#{self[key].inspect}"
@@ -1,141 +1,105 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
1
+ require 'spec_helper'
2
2
 
3
- describe ActiveResource::Connection do
4
- before do
3
+ class Customer < ActiveResource::Base
4
+ self.site = ''
5
+ end
6
+
7
+ describe Customer do
8
+ before(:each) do
5
9
  Dupe.reset
6
10
  end
7
11
 
8
- describe "#get" do
9
- before do
10
- @book = Dupe.create :book, :title => 'Rooby', :label => 'rooby'
11
- class Book < ActiveResource::Base
12
- self.site = ''
13
- end
12
+ it "should have none url patterns registered" do
13
+ [:post, :get, :delete, :put].each do |verb|
14
+ Dupe.network.mocks[verb].should be_blank
14
15
  end
15
-
16
- it "should pass a request off to the Dupe network if the original request failed" do
17
- Dupe.network.should_receive(:request).with(:get, '/books.xml').once.and_return(Dupe.find(:books).to_xml(:root => 'books'))
18
- books = Book.find(:all)
16
+ end
17
+
18
+
19
+ context "registerd" do
20
+ before(:each) do
21
+ Dupe.create Customer, :name => 'Ribi', :state => 'active'
19
22
  end
20
-
21
- it "should parse the xml and turn the result into active resource objects" do
22
- books = Book.find(:all)
23
- books.length.should == 1
24
- books.first.id.should == 1
25
- books.first.title.should == 'Rooby'
26
- books.first.label.should == 'rooby'
23
+
24
+ it "should be registered as get mock" do
25
+ Dupe.network.mocks[:get].size == 2
27
26
  end
28
- end
29
27
 
30
- describe "#post" do
31
- before do
32
- @book = Dupe.create :book, :label => 'rooby', :title => 'Rooby'
33
- @book.delete(:id)
34
- class Book < ActiveResource::Base
35
- self.site = ''
36
- end
28
+ it "should generate a GetMock" do
29
+ customer = Dupe.find :"Customer"
30
+ customer.should_not be_nil
31
+ customer.class.should == Dupe::Database::Record
37
32
  end
38
33
 
39
- it "should pass a request off to the Dupe network if the original request failed" do
40
- Dupe.network.should_receive(:request).with(:post, '/books.xml', Hash.from_xml(@book.to_xml(:root => 'book'))["book"] ).once
41
- book = Book.create({:label => 'rooby', :title => 'Rooby'})
34
+ it "should generate a valid url pattern" do
35
+ Dupe.network.mocks[:get].each_with_index do |mock, index|
36
+ mock.url_pattern.class.should == Regexp
37
+ if index == 0
38
+ mock.url_pattern.inspect.should == (%r{^\/customers\.xml$}).inspect
39
+ else
40
+ mock.url_pattern.inspect.should == %r{^\/customers\/(\d+)\.xml$}.inspect
41
+ end
42
+ end
42
43
  end
43
44
 
44
- it "should parse the xml and turn the result into active resource objects" do
45
- book = Book.create({:label => 'rooby', :title => 'Rooby'})
46
- book.id.should == 2
47
- book.title.should == 'Rooby'
48
- book.label.should == 'rooby'
49
- end
50
45
 
51
- it "should make ActiveResource throw an unprocessable entity exception if our Post mock throws a Dupe::UnprocessableEntity exception" do
52
- Post %r{/books\.xml} do |post_data|
53
- raise Dupe::UnprocessableEntity.new(:title => "must be present.") unless post_data["title"]
54
- Dupe.create :book, post_data
55
- end
46
+ context "find single resource" do
47
+ before(:each) { @customer = Customer.find 1 }
56
48
 
57
- b = Book.create
58
- b.new?.should be_true
59
- b.errors.errors.should_not be_empty
60
- b = Book.create(:title => "hello")
61
- b.new?.should be_false
62
- b.errors.should be_empty
63
- end
64
- end
65
-
66
- describe "#put" do
67
- before do
68
- @book = Dupe.create :book, :label => 'rooby', :title => 'Rooby'
69
- class Book < ActiveResource::Base
70
- self.site = ''
49
+ it "should find customer with id 1" do
50
+ @customer.should_not be_blank
71
51
  end
72
- @ar_book = Book.find(1)
73
52
  end
74
53
 
75
- it "should pass a request off to the Dupe network if the original request failed" do
76
- Dupe.network.should_receive(:request).with(:put, '/books/1.xml', Hash.from_xml(@book.merge(:title => "Rails!").to_xml(:root => 'book'))["book"].symbolize_keys!).once
77
- @ar_book.title = 'Rails!'
78
- @ar_book.save
79
- end
80
-
81
- it "should parse the xml and turn the result into active resource objects" do
82
- @book.title.should == "Rooby"
83
- @ar_book.title = "Rails!"
84
- @ar_book.save
85
- @ar_book.new?.should == false
86
- @ar_book.valid?.should == true
87
- @ar_book.id.should == 1
88
- @ar_book.label.should == "rooby"
89
- @book.title.should == "Rails!"
90
- @book.id.should == 1
91
- @book.label.should == 'rooby'
92
- end
93
54
 
94
- it "should make ActiveResource throw an unprocessable entity exception if our Put mock throws a Dupe::UnprocessableEntity exception" do
95
- Put %r{/books/(\d+)\.xml} do |id, put_data|
96
- raise Dupe::UnprocessableEntity.new(:title => " must be present.") unless put_data[:title]
97
- Dupe.find(:book) {|b| b.id == id.to_i}.merge!(put_data)
55
+ context "find every resource" do
56
+ before(:each) { @customers = Customer.find :all }
57
+
58
+ it "should return an array" do
59
+ @customers.class.should == Array
98
60
  end
99
61
 
100
- @ar_book.title = nil
101
- @ar_book.save.should == false
102
- @ar_book.errors.on_base.should_not be_empty
103
-
104
- @ar_book.title = "Rails!"
105
- @ar_book.save.should == true
106
- # the following line should be true, were it not for a bug in active_resource 2.3.3 - 2.3.5
107
- # i reported the bug here: https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/4169-activeresourcebasesave-put-doesnt-clear-out-errors
108
- # @ar_book.errors.should be_empty
109
- end
110
- end
111
-
112
- describe "#delete" do
113
- before do
114
- @book = Dupe.create :book, :label => 'rooby', :title => 'Rooby'
115
- class Book < ActiveResource::Base
116
- self.site = ''
62
+ it "should include customer number one" do
63
+ @customers.should be_include(Customer.find(1))
64
+ end
65
+
66
+ it "should have size of one" do
67
+ @customers.size.should == 1
117
68
  end
118
- @ar_book = Book.find(1)
119
69
  end
120
70
 
121
- it "should pass a request off to the Dupe network if the original request failed" do
122
- Dupe.network.should_receive(:request).with(:delete, '/books/1.xml').once
123
- @ar_book.destroy
124
- end
125
71
 
126
- it "trigger a Dupe.delete to delete the mocked resource from the duped database" do
127
- Dupe.find(:books).length.should == 1
128
- @ar_book.destroy
129
- Dupe.find(:books).length.should == 0
130
- end
131
-
132
- it "should allow you to override the default DELETE intercept mock" do
133
- Delete %r{/books/(\d+)\.xml} do |id|
134
- raise StandardError, "Testing Delete override"
72
+ context "find every resource with a param-filter" do
73
+ before(:each) do
74
+ Dupe.create Customer, :name => 'Marco', :state => 'inactive'
75
+ Get %r{\/customers\.xml\?state=(active|inactive)} do |state|
76
+ if state == 'active'
77
+ Dupe.find(:"Customers") {|customer| customer.state == 'active'}
78
+ elsif state == 'inactive'
79
+ Dupe.find(:"Customers") {|customer| customer.state == 'inactive'}
80
+ else
81
+ Dupe.find(:"Customers")
82
+ end
83
+ end
84
+ end
85
+
86
+ it "should find all active customers" do
87
+ active_customers = Customer.find :all, :params => {:state => 'active'}
88
+ active_customers.size.should == 1
89
+ active_customers.should be_include(Customer.find(1))
90
+ end
91
+
92
+ it "should find all inactive customers" do
93
+ inactive_customers = Customer.find :all, :params => {:state => 'inactive'}
94
+ inactive_customers.size.should == 1
95
+ inactive_customers.should be_include(Customer.find(2))
96
+ end
97
+
98
+ it "should find all customers without a filter" do
99
+ customers = Customer.find :all, :params => {}
100
+ customers.size.should == 2
101
+ customers.should == Customer.find(:all)
135
102
  end
136
-
137
- proc {@ar_book.destroy}.should raise_error(StandardError, "Testing Delete override")
138
103
  end
139
104
  end
140
-
141
- end
105
+ end
data/spec/spec_helper.rb CHANGED
@@ -5,4 +5,4 @@ gem 'rspec'
5
5
  gem 'cucumber'
6
6
  require 'cucumber'
7
7
  require 'active_resource'
8
- require 'dupe'
8
+ require 'superdupe'
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: superdupe
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
4
+ hash: 11
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 4
8
+ - 5
9
9
  - 0
10
- version: 0.4.0
10
+ version: 0.5.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Marco Ribi
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-09-02 00:00:00 +02:00
18
+ date: 2010-09-10 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -70,22 +70,6 @@ files:
70
70
  - rails_generators/dupe/templates/definitions.rb
71
71
  - rails_generators/dupe/templates/load_dupe.rb
72
72
  - spec/lib_specs/active_resource_extensions_spec.rb
73
- - spec/lib_specs/attribute_template_spec.rb
74
- - spec/lib_specs/database_spec.rb
75
- - spec/lib_specs/dupe_spec.rb
76
- - spec/lib_specs/hash_pruner_spec.rb
77
- - spec/lib_specs/log_spec.rb
78
- - spec/lib_specs/logged_request_spec.rb
79
- - spec/lib_specs/mock_definitions_spec.rb
80
- - spec/lib_specs/mock_spec.rb
81
- - spec/lib_specs/model_spec.rb
82
- - spec/lib_specs/network_spec.rb
83
- - spec/lib_specs/record_spec.rb
84
- - spec/lib_specs/rest_validation_spec.rb
85
- - spec/lib_specs/schema_spec.rb
86
- - spec/lib_specs/sequence_spec.rb
87
- - spec/lib_specs/string_spec.rb
88
- - spec/lib_specs/symbol_spec.rb
89
73
  - spec/spec_helper.rb
90
74
  has_rdoc: true
91
75
  homepage: http://github.com/screenconcept/dupe
@@ -123,20 +107,4 @@ specification_version: 3
123
107
  summary: A tool that helps you mock services while cuking.
124
108
  test_files:
125
109
  - spec/lib_specs/active_resource_extensions_spec.rb
126
- - spec/lib_specs/attribute_template_spec.rb
127
- - spec/lib_specs/database_spec.rb
128
- - spec/lib_specs/dupe_spec.rb
129
- - spec/lib_specs/hash_pruner_spec.rb
130
- - spec/lib_specs/log_spec.rb
131
- - spec/lib_specs/logged_request_spec.rb
132
- - spec/lib_specs/mock_definitions_spec.rb
133
- - spec/lib_specs/mock_spec.rb
134
- - spec/lib_specs/model_spec.rb
135
- - spec/lib_specs/network_spec.rb
136
- - spec/lib_specs/record_spec.rb
137
- - spec/lib_specs/rest_validation_spec.rb
138
- - spec/lib_specs/schema_spec.rb
139
- - spec/lib_specs/sequence_spec.rb
140
- - spec/lib_specs/string_spec.rb
141
- - spec/lib_specs/symbol_spec.rb
142
110
  - spec/spec_helper.rb
@@ -1,173 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
-
3
- describe Dupe::Model::Schema::AttributeTemplate do
4
- describe "new" do
5
- it "should require a name" do
6
- proc {
7
- Dupe::Model::Schema::AttributeTemplate.new
8
- }.should raise_error(ArgumentError)
9
- end
10
-
11
- it "should set the name if one is passed to it" do
12
- attribute = Dupe::Model::Schema::AttributeTemplate.new(:title)
13
- attribute.name.should == :title
14
- end
15
-
16
- it "should set a default value if one is passed to it" do
17
- attribute =
18
- Dupe::Model::Schema::AttributeTemplate.new(
19
- :title,
20
- :default => 'Untitled'
21
- )
22
- attribute.default.should == 'Untitled'
23
- end
24
-
25
- it "should verify that the transformer is a proc" do
26
- proc {
27
- attribute =
28
- Dupe::Model::Schema::AttributeTemplate.new(
29
- :title,
30
- :default => nil,
31
- :transformer => 'not a proc'
32
- )
33
- }.should raise_error(
34
- ArgumentError,
35
- "Your transformer must be a kind of proc."
36
- )
37
- end
38
-
39
- it "should verify that the transformer requires a single parameter" do
40
- proc {
41
- attribute = Dupe::Model::Schema::AttributeTemplate.new(
42
- :title,
43
- :default => nil,
44
- :transformer => proc {'test'}
45
- )
46
- }.should raise_error(
47
- ArgumentError,
48
- "Your transformer must accept a parameter."
49
- )
50
- end
51
-
52
- it "should set the transformer if one is passed" do
53
- transformer = proc {|dont_care| }
54
- attribute = Dupe::Model::Schema::AttributeTemplate.new(
55
- :title,
56
- :default => nil,
57
- :transformer => transformer
58
- )
59
- attribute.transformer.should == transformer
60
- end
61
- end
62
-
63
- describe "generate" do
64
- describe "on an attribute without a default value and without a transformer" do
65
- before do
66
- @attribute = Dupe::Model::Schema::AttributeTemplate.new(:title)
67
- end
68
-
69
- it "should generate a key with the name of the attribute" do
70
- key, value = @attribute.generate
71
- key.should == @attribute.name
72
- end
73
-
74
- describe "when passed nothing" do
75
- it "should generate a nil value" do
76
- key, value = @attribute.generate
77
- value.should == nil
78
- end
79
- end
80
-
81
- describe "when passed a value" do
82
- it "should generate a value equal to the value passed in" do
83
- key, value = @attribute.generate('test')
84
- value.should == 'test'
85
- end
86
- end
87
- end
88
-
89
- describe "on an attribute with a default value but without a transformer" do
90
- before do
91
- @attribute = Dupe::Model::Schema::AttributeTemplate.new(:title, :default => 'Untitled')
92
- end
93
-
94
- it "should generate a key with the name of the attribute" do
95
- key, value = @attribute.generate
96
- key.should == @attribute.name
97
- end
98
-
99
- describe "when passed nothing" do
100
- it "should generate a value equal to the default value" do
101
- key, value = @attribute.generate
102
- value.should == @attribute.default
103
- end
104
- end
105
-
106
- describe "when passed a value" do
107
- it "should generate a value equal to the value passed in" do
108
- title = '2001: A Space Odyssey'
109
- key, value = @attribute.generate title
110
- value.should == title
111
- end
112
- end
113
- end
114
-
115
- describe "on an attribute with a default value that is a proc" do
116
- before do
117
- @default_value = proc { 'knock' * 3 }
118
- @attribute = Dupe::Model::Schema::AttributeTemplate.new(:title, :default => @default_value)
119
- end
120
-
121
- it "should generate a key with the name of the attribute" do
122
- key, value = @attribute.generate
123
- key.should == @attribute.name
124
- end
125
-
126
- describe "when passed nothing" do
127
- it "should return the value of the default_value proc" do
128
- key, value = @attribute.generate
129
- value.should == @default_value.call
130
- end
131
- end
132
-
133
- describe "when passed a value" do
134
- it "should generate a value equal to the value passed in" do
135
- title = 'Rooby'
136
- key, value = @attribute.generate title
137
- value.should == title
138
- end
139
- end
140
-
141
- end
142
-
143
- describe "on an attribute with a transformer" do
144
- before do
145
- @transformer = proc {|dont_care| 'test'}
146
- @attribute = Dupe::Model::Schema::AttributeTemplate.new(
147
- :title,
148
- :default => nil,
149
- :transformer => @transformer
150
- )
151
- end
152
-
153
- it "should generate a key with the name of the attribute" do
154
- key, value = @attribute.generate
155
- key.should == @attribute.name
156
- end
157
-
158
- describe "when passed nothing" do
159
- it "should generate a value equal to the default" do
160
- key, value = @attribute.generate
161
- value.should == @attribute.default
162
- end
163
- end
164
-
165
- describe "when passed a value" do
166
- it "should generate a value equal to the value returned by the transformer" do
167
- key, value = @attribute.generate 'blah'
168
- value.should == @transformer.call('blah')
169
- end
170
- end
171
- end
172
- end
173
- end