draper 0.12.3 → 0.13.0

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml CHANGED
@@ -1,6 +1,4 @@
1
1
  rvm:
2
- - 1.8.7
3
- - 1.9.2
4
- - rbx
5
- - ree
6
- - jruby
2
+ - 1.9.3
3
+ # - rbx-19mode # not until rbx bug #1692 is resolved
4
+ - jruby-19mode
data/CHANGELOG.txt CHANGED
@@ -1,16 +1,25 @@
1
1
  = Draper Changelog
2
2
 
3
- = Master
3
+ = 0.13.0
4
4
 
5
- == v0.12.3
5
+ * Upgraded all dependencies
6
6
 
7
- * Fix i18n issue, see #202
7
+ * Dropped support for Rubies < 1.9.3
8
8
 
9
- == v0.12.2
9
+ * #to_model has been renamed to #wrapped_object
10
10
 
11
- * Backport 738074f, which fixes Rails console
11
+ * Allow proper overriding of special ActiveModel methods
12
12
 
13
- == 0.12.1
13
+ == 0.12.2
14
+
15
+ * Fix bug with initializing ammeter
16
+
17
+ * Some gems are now development only in the gemspec
18
+
19
+ * Fix bug where generated models were still inheriting from
20
+ ApplicationDecorator
21
+
22
+ == 0.12.0
14
23
 
15
24
  * Added Changelog
16
25
 
data/draper.gemspec CHANGED
@@ -16,11 +16,11 @@ Gem::Specification.new do |s|
16
16
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
17
  s.require_paths = ["lib"]
18
18
 
19
- s.add_dependency 'activesupport', '>= 2.3.10'
20
- s.add_dependency 'rake'
21
- s.add_dependency 'rspec', '~> 2.0'
22
- s.add_dependency 'activesupport', '~> 3.1.3'
23
- s.add_dependency 'actionpack', "~> 3.1.3"
19
+ s.add_dependency 'activesupport', '~> 3.2'
20
+ s.add_dependency 'rake', '~> 0.9.2'
21
+ s.add_dependency 'rspec', '~> 2.10'
22
+ s.add_dependency 'activesupport', '~> 3.2'
23
+ s.add_dependency 'actionpack', '~> 3.2'
24
24
 
25
25
  s.add_development_dependency 'ammeter', '~> 0.2.2'
26
26
  s.add_development_dependency 'guard'
@@ -1,6 +1,6 @@
1
1
  module Draper::ActiveModelSupport
2
2
  module Proxies
3
- def create_proxies
3
+ def self.extended(base)
4
4
  # These methods (as keys) will be created only if the correspondent
5
5
  # model descends from a specific class (as value)
6
6
  proxies = {}
@@ -9,16 +9,24 @@ module Draper::ActiveModelSupport
9
9
  proxies[:id] = ActiveRecord::Base if defined?(ActiveRecord::Base)
10
10
 
11
11
  proxies.each do |method_name, dependency|
12
- if model.kind_of?(dependency) || dependency.nil?
13
- class << self
12
+ if base.model.kind_of?(dependency) || dependency.nil?
13
+ class << base
14
14
  self
15
15
  end.class_eval do
16
- self.send(:define_method, method_name) do |*args, &block|
17
- model.send(method_name, *args, &block)
16
+ if !base.class.instance_methods.include?(method_name) || base.class.instance_method(method_name).owner === Draper::Base
17
+ send(:define_method, method_name) do |*args, &block|
18
+ model.send(method_name, *args, &block)
19
+ end
18
20
  end
19
21
  end
20
22
  end
21
23
  end
24
+
25
+ base.class_eval do
26
+ def to_model
27
+ self
28
+ end
29
+ end
22
30
  end
23
31
  end
24
32
  end
data/lib/draper/base.rb CHANGED
@@ -11,7 +11,7 @@ module Draper
11
11
  self.denied = DEFAULT_DENIED
12
12
  self.allowed = DEFAULT_ALLOWED
13
13
 
14
- include Draper::ActiveModelSupport::Proxies
14
+
15
15
 
16
16
  # Initialize a new decorator instance by passing in
17
17
  # an instance of the source class. Pass in an optional
@@ -24,7 +24,7 @@ module Draper
24
24
  self.class.model_class = input.class if model_class.nil?
25
25
  @model = input.kind_of?(Draper::Base) ? input.model : input
26
26
  self.options = options
27
- create_proxies
27
+ self.extend Draper::ActiveModelSupport::Proxies
28
28
  end
29
29
 
30
30
  # Proxies to the class specified by `decorates` to automatically
@@ -191,7 +191,7 @@ module Draper
191
191
  # Fetch the original wrapped model.
192
192
  #
193
193
  # @return [Object] original_model
194
- def to_model
194
+ def wrapped_object
195
195
  @model
196
196
  end
197
197
 
@@ -30,7 +30,7 @@ module Draper
30
30
  # This is the standard "Rails Way" to add paths from which constants
31
31
  # can be loaded.
32
32
  #
33
- config.after_initialize do |app|
33
+ config.before_initialize do |app|
34
34
  app.config.paths.add 'app/decorators', :eager_load => true
35
35
  end
36
36
 
@@ -46,12 +46,5 @@ module Draper
46
46
  end
47
47
  end
48
48
 
49
- console do
50
- require 'action_controller/test_case'
51
- ApplicationController.new.set_current_view_context
52
- Draper::ViewContext.current.controller.request ||= ActionController::TestRequest.new
53
- Draper::ViewContext.current.request ||= Draper::ViewContext.current.controller.request
54
- Draper::ViewContext.current.params ||= {}
55
- end
56
49
  end
57
50
  end
@@ -1,3 +1,3 @@
1
1
  module Draper
2
- VERSION = "0.12.3"
2
+ VERSION = "0.13.0"
3
3
  end
@@ -182,10 +182,9 @@ describe Draper::Base do
182
182
  end
183
183
  end
184
184
 
185
- context(".model / .to_model") do
185
+ context(".wrapped_object") do
186
186
  it "should return the wrapped object" do
187
- subject.to_model.should == source
188
- subject.model.should == source
187
+ subject.wrapped_object.should == source
189
188
  end
190
189
  end
191
190
 
@@ -216,19 +215,33 @@ describe Draper::Base do
216
215
  end
217
216
 
218
217
  context "when an ActiveModel descendant" do
219
- it "should always proxy to_param" do
218
+ it "should always proxy to_param if it is not defined on the decorator itself" do
220
219
  source.stub(:to_param).and_return(1)
221
220
  Draper::Base.new(source).to_param.should == 1
222
221
  end
223
222
 
224
- it "should always proxy id" do
223
+ it "should always proxy id if it is not defined on the decorator itself" do
225
224
  source.stub(:id).and_return(123456789)
226
225
  Draper::Base.new(source).id.should == 123456789
227
226
  end
228
227
 
229
- it "should always proxy errors" do
228
+ it "should always proxy errors if it is not defined on the decorator itself" do
230
229
  Draper::Base.new(source).errors.should be_an_instance_of ActiveModel::Errors
231
230
  end
231
+
232
+ it "should never proxy to_param if it is defined on the decorator itself" do
233
+ source.stub(:to_param).and_return(1)
234
+ DecoratorWithSpecialMethods.new(source).to_param.should == "foo"
235
+ end
236
+
237
+ it "should never proxy id if it is defined on the decorator itself" do
238
+ source.stub(:id).and_return(123456789)
239
+ DecoratorWithSpecialMethods.new(source).id.should == 1337
240
+ end
241
+
242
+ it "should never proxy errors if it is defined on the decorator itself" do
243
+ DecoratorWithSpecialMethods.new(source).errors.should be_an_instance_of Array
244
+ end
232
245
  end
233
246
 
234
247
  context "when not an ActiveModel descendant" do
data/spec/spec_helper.rb CHANGED
@@ -14,6 +14,7 @@ require './spec/support/samples/decorator_with_allows'
14
14
  require './spec/support/samples/decorator_with_multiple_allows'
15
15
  require './spec/support/samples/decorator_with_application_helper'
16
16
  require './spec/support/samples/decorator_with_denies'
17
+ require './spec/support/samples/decorator_with_special_methods'
17
18
  require './spec/support/samples/namespaced_product'
18
19
  require './spec/support/samples/namespaced_product_decorator'
19
20
  require './spec/support/samples/non_active_model_product'
File without changes
@@ -0,0 +1,13 @@
1
+ class DecoratorWithSpecialMethods < Draper::Base
2
+ def to_param
3
+ "foo"
4
+ end
5
+
6
+ def id
7
+ 1337
8
+ end
9
+
10
+ def errors
11
+ ["omg errors!"]
12
+ end
13
+ end
metadata CHANGED
@@ -1,185 +1,182 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: draper
3
- version: !ruby/object:Gem::Version
4
- version: 0.12.3
3
+ version: !ruby/object:Gem::Version
4
+ hash: 43
5
5
  prerelease:
6
+ segments:
7
+ - 0
8
+ - 13
9
+ - 0
10
+ version: 0.13.0
6
11
  platform: ruby
7
- authors:
12
+ authors:
8
13
  - Jeff Casimir
9
14
  - Steve Klabnik
10
15
  autorequire:
11
16
  bindir: bin
12
17
  cert_chain: []
13
- date: 2012-05-15 00:00:00.000000000 Z
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
18
+
19
+ date: 2012-05-12 00:00:00 Z
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
16
22
  name: activesupport
17
- requirement: !ruby/object:Gem::Requirement
18
- none: false
19
- requirements:
20
- - - ! '>='
21
- - !ruby/object:Gem::Version
22
- version: 2.3.10
23
- type: :runtime
24
23
  prerelease: false
25
- version_requirements: !ruby/object:Gem::Requirement
24
+ requirement: &id001 !ruby/object:Gem::Requirement
26
25
  none: false
27
- requirements:
28
- - - ! '>='
29
- - !ruby/object:Gem::Version
30
- version: 2.3.10
31
- - !ruby/object:Gem::Dependency
32
- name: rake
33
- requirement: !ruby/object:Gem::Requirement
34
- none: false
35
- requirements:
36
- - - ! '>='
37
- - !ruby/object:Gem::Version
38
- version: '0'
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 3
32
+ - 2
33
+ version: "3.2"
39
34
  type: :runtime
35
+ version_requirements: *id001
36
+ - !ruby/object:Gem::Dependency
37
+ name: rake
40
38
  prerelease: false
41
- version_requirements: !ruby/object:Gem::Requirement
42
- none: false
43
- requirements:
44
- - - ! '>='
45
- - !ruby/object:Gem::Version
46
- version: '0'
47
- - !ruby/object:Gem::Dependency
48
- name: rspec
49
- requirement: !ruby/object:Gem::Requirement
39
+ requirement: &id002 !ruby/object:Gem::Requirement
50
40
  none: false
51
- requirements:
41
+ requirements:
52
42
  - - ~>
53
- - !ruby/object:Gem::Version
54
- version: '2.0'
43
+ - !ruby/object:Gem::Version
44
+ hash: 63
45
+ segments:
46
+ - 0
47
+ - 9
48
+ - 2
49
+ version: 0.9.2
55
50
  type: :runtime
51
+ version_requirements: *id002
52
+ - !ruby/object:Gem::Dependency
53
+ name: rspec
56
54
  prerelease: false
57
- version_requirements: !ruby/object:Gem::Requirement
55
+ requirement: &id003 !ruby/object:Gem::Requirement
58
56
  none: false
59
- requirements:
57
+ requirements:
60
58
  - - ~>
61
- - !ruby/object:Gem::Version
62
- version: '2.0'
63
- - !ruby/object:Gem::Dependency
64
- name: activesupport
65
- requirement: !ruby/object:Gem::Requirement
66
- none: false
67
- requirements:
68
- - - ~>
69
- - !ruby/object:Gem::Version
70
- version: 3.1.3
59
+ - !ruby/object:Gem::Version
60
+ hash: 23
61
+ segments:
62
+ - 2
63
+ - 10
64
+ version: "2.10"
71
65
  type: :runtime
66
+ version_requirements: *id003
67
+ - !ruby/object:Gem::Dependency
68
+ name: activesupport
72
69
  prerelease: false
73
- version_requirements: !ruby/object:Gem::Requirement
70
+ requirement: &id004 !ruby/object:Gem::Requirement
74
71
  none: false
75
- requirements:
72
+ requirements:
76
73
  - - ~>
77
- - !ruby/object:Gem::Version
78
- version: 3.1.3
79
- - !ruby/object:Gem::Dependency
80
- name: actionpack
81
- requirement: !ruby/object:Gem::Requirement
82
- none: false
83
- requirements:
84
- - - ~>
85
- - !ruby/object:Gem::Version
86
- version: 3.1.3
74
+ - !ruby/object:Gem::Version
75
+ hash: 3
76
+ segments:
77
+ - 3
78
+ - 2
79
+ version: "3.2"
87
80
  type: :runtime
81
+ version_requirements: *id004
82
+ - !ruby/object:Gem::Dependency
83
+ name: actionpack
88
84
  prerelease: false
89
- version_requirements: !ruby/object:Gem::Requirement
85
+ requirement: &id005 !ruby/object:Gem::Requirement
90
86
  none: false
91
- requirements:
87
+ requirements:
92
88
  - - ~>
93
- - !ruby/object:Gem::Version
94
- version: 3.1.3
95
- - !ruby/object:Gem::Dependency
89
+ - !ruby/object:Gem::Version
90
+ hash: 3
91
+ segments:
92
+ - 3
93
+ - 2
94
+ version: "3.2"
95
+ type: :runtime
96
+ version_requirements: *id005
97
+ - !ruby/object:Gem::Dependency
96
98
  name: ammeter
97
- requirement: !ruby/object:Gem::Requirement
98
- none: false
99
- requirements:
100
- - - ~>
101
- - !ruby/object:Gem::Version
102
- version: 0.2.2
103
- type: :development
104
99
  prerelease: false
105
- version_requirements: !ruby/object:Gem::Requirement
100
+ requirement: &id006 !ruby/object:Gem::Requirement
106
101
  none: false
107
- requirements:
102
+ requirements:
108
103
  - - ~>
109
- - !ruby/object:Gem::Version
104
+ - !ruby/object:Gem::Version
105
+ hash: 19
106
+ segments:
107
+ - 0
108
+ - 2
109
+ - 2
110
110
  version: 0.2.2
111
- - !ruby/object:Gem::Dependency
112
- name: guard
113
- requirement: !ruby/object:Gem::Requirement
114
- none: false
115
- requirements:
116
- - - ! '>='
117
- - !ruby/object:Gem::Version
118
- version: '0'
119
111
  type: :development
112
+ version_requirements: *id006
113
+ - !ruby/object:Gem::Dependency
114
+ name: guard
120
115
  prerelease: false
121
- version_requirements: !ruby/object:Gem::Requirement
122
- none: false
123
- requirements:
124
- - - ! '>='
125
- - !ruby/object:Gem::Version
126
- version: '0'
127
- - !ruby/object:Gem::Dependency
128
- name: guard-rspec
129
- requirement: !ruby/object:Gem::Requirement
116
+ requirement: &id007 !ruby/object:Gem::Requirement
130
117
  none: false
131
- requirements:
132
- - - ! '>='
133
- - !ruby/object:Gem::Version
134
- version: '0'
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ hash: 3
122
+ segments:
123
+ - 0
124
+ version: "0"
135
125
  type: :development
126
+ version_requirements: *id007
127
+ - !ruby/object:Gem::Dependency
128
+ name: guard-rspec
136
129
  prerelease: false
137
- version_requirements: !ruby/object:Gem::Requirement
138
- none: false
139
- requirements:
140
- - - ! '>='
141
- - !ruby/object:Gem::Version
142
- version: '0'
143
- - !ruby/object:Gem::Dependency
144
- name: launchy
145
- requirement: !ruby/object:Gem::Requirement
130
+ requirement: &id008 !ruby/object:Gem::Requirement
146
131
  none: false
147
- requirements:
148
- - - ! '>='
149
- - !ruby/object:Gem::Version
150
- version: '0'
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ hash: 3
136
+ segments:
137
+ - 0
138
+ version: "0"
151
139
  type: :development
140
+ version_requirements: *id008
141
+ - !ruby/object:Gem::Dependency
142
+ name: launchy
152
143
  prerelease: false
153
- version_requirements: !ruby/object:Gem::Requirement
144
+ requirement: &id009 !ruby/object:Gem::Requirement
154
145
  none: false
155
- requirements:
156
- - - ! '>='
157
- - !ruby/object:Gem::Version
158
- version: '0'
159
- - !ruby/object:Gem::Dependency
160
- name: yard
161
- requirement: !ruby/object:Gem::Requirement
162
- none: false
163
- requirements:
164
- - - ! '>='
165
- - !ruby/object:Gem::Version
166
- version: '0'
146
+ requirements:
147
+ - - ">="
148
+ - !ruby/object:Gem::Version
149
+ hash: 3
150
+ segments:
151
+ - 0
152
+ version: "0"
167
153
  type: :development
154
+ version_requirements: *id009
155
+ - !ruby/object:Gem::Dependency
156
+ name: yard
168
157
  prerelease: false
169
- version_requirements: !ruby/object:Gem::Requirement
158
+ requirement: &id010 !ruby/object:Gem::Requirement
170
159
  none: false
171
- requirements:
172
- - - ! '>='
173
- - !ruby/object:Gem::Version
174
- version: '0'
160
+ requirements:
161
+ - - ">="
162
+ - !ruby/object:Gem::Version
163
+ hash: 3
164
+ segments:
165
+ - 0
166
+ version: "0"
167
+ type: :development
168
+ version_requirements: *id010
175
169
  description: Draper implements a decorator or presenter pattern for Rails applications.
176
- email:
170
+ email:
177
171
  - jeff@casimircreative.com
178
172
  - steve@steveklabnik.com
179
173
  executables: []
174
+
180
175
  extensions: []
176
+
181
177
  extra_rdoc_files: []
182
- files:
178
+
179
+ files:
183
180
  - .gitignore
184
181
  - .rspec
185
182
  - .travis.yml
@@ -249,6 +246,7 @@ files:
249
246
  - spec/support/samples/decorator_with_application_helper.rb
250
247
  - spec/support/samples/decorator_with_denies.rb
251
248
  - spec/support/samples/decorator_with_multiple_allows.rb
249
+ - spec/support/samples/decorator_with_special_methods.rb
252
250
  - spec/support/samples/namespaced_product.rb
253
251
  - spec/support/samples/namespaced_product_decorator.rb
254
252
  - spec/support/samples/non_active_model_product.rb
@@ -261,29 +259,38 @@ files:
261
259
  - spec/support/samples/widget_decorator.rb
262
260
  homepage: http://github.com/jcasimir/draper
263
261
  licenses: []
262
+
264
263
  post_install_message:
265
264
  rdoc_options: []
266
- require_paths:
265
+
266
+ require_paths:
267
267
  - lib
268
- required_ruby_version: !ruby/object:Gem::Requirement
268
+ required_ruby_version: !ruby/object:Gem::Requirement
269
269
  none: false
270
- requirements:
271
- - - ! '>='
272
- - !ruby/object:Gem::Version
273
- version: '0'
274
- required_rubygems_version: !ruby/object:Gem::Requirement
270
+ requirements:
271
+ - - ">="
272
+ - !ruby/object:Gem::Version
273
+ hash: 3
274
+ segments:
275
+ - 0
276
+ version: "0"
277
+ required_rubygems_version: !ruby/object:Gem::Requirement
275
278
  none: false
276
- requirements:
277
- - - ! '>='
278
- - !ruby/object:Gem::Version
279
- version: '0'
279
+ requirements:
280
+ - - ">="
281
+ - !ruby/object:Gem::Version
282
+ hash: 3
283
+ segments:
284
+ - 0
285
+ version: "0"
280
286
  requirements: []
287
+
281
288
  rubyforge_project: draper
282
289
  rubygems_version: 1.8.24
283
290
  signing_key:
284
291
  specification_version: 3
285
292
  summary: Decorator pattern implementation for Rails.
286
- test_files:
293
+ test_files:
287
294
  - spec/draper/base_spec.rb
288
295
  - spec/draper/helper_support_spec.rb
289
296
  - spec/draper/model_support_spec.rb
@@ -299,6 +306,7 @@ test_files:
299
306
  - spec/support/samples/decorator_with_application_helper.rb
300
307
  - spec/support/samples/decorator_with_denies.rb
301
308
  - spec/support/samples/decorator_with_multiple_allows.rb
309
+ - spec/support/samples/decorator_with_special_methods.rb
302
310
  - spec/support/samples/namespaced_product.rb
303
311
  - spec/support/samples/namespaced_product_decorator.rb
304
312
  - spec/support/samples/non_active_model_product.rb