draper 0.8.0 → 0.8.1

Sign up to get free protection for your applications and to get access to all the features.
data/lib/draper/base.rb CHANGED
@@ -115,14 +115,6 @@ module Draper
115
115
  self.send(:include, Draper::LazyHelpers)
116
116
  end
117
117
 
118
- # Use primarily by `form_for`, this returns an instance of
119
- # `ActiveModel::Name` set to the wrapped model's class name
120
- #
121
- # @return [ActiveModel::Name] model_name
122
- def self.model_name
123
- ActiveModel::Name.new(model_class)
124
- end
125
-
126
118
  # Fetch the original wrapped model.
127
119
  #
128
120
  # @return [Object] original_model
@@ -137,7 +129,7 @@ module Draper
137
129
  @model == other.model
138
130
  end
139
131
 
140
- def respond_to?(method)
132
+ def respond_to?(method, include_private = false)
141
133
  if select_methods.include?(method)
142
134
  model.respond_to?(method)
143
135
  else
@@ -152,6 +144,14 @@ module Draper
152
144
  super
153
145
  end
154
146
  end
147
+
148
+ def self.method_missing(method, *args, &block)
149
+ model_class.send(method, *args, &block)
150
+ end
151
+
152
+ def self.respond_to?(method, include_private = false)
153
+ super || model_class.respond_to?(method)
154
+ end
155
155
 
156
156
  private
157
157
  def select_methods
@@ -1,3 +1,3 @@
1
1
  module Draper
2
- VERSION = "0.8.0"
2
+ VERSION = "0.8.1"
3
3
  end
data/spec/base_spec.rb CHANGED
@@ -3,9 +3,23 @@ require 'draper'
3
3
 
4
4
  describe Draper::Base do
5
5
  before(:each){ ApplicationController.new.set_current_view_context }
6
- subject{ Draper::Base.new(source) }
6
+ subject{ Decorator.new(source) }
7
7
  let(:source){ Product.new }
8
8
 
9
+ context("proxying class methods") do
10
+ it "should pass missing class method calls on to the wrapped class" do
11
+ subject.class.sample_class_method.should == "sample class method"
12
+ end
13
+
14
+ it "should respond_to a wrapped class method" do
15
+ subject.class.should respond_to(:sample_class_method)
16
+ end
17
+
18
+ it "should still respond_to it's own class methods" do
19
+ subject.class.should respond_to(:own_class_method)
20
+ end
21
+ end
22
+
9
23
  context(".helpers") do
10
24
  it "should have a valid view_context" do
11
25
  subject.helpers.should be
@@ -19,12 +33,6 @@ describe Draper::Base do
19
33
  end
20
34
  end
21
35
 
22
- context(".model_name") do
23
- it "should return an ActiveModel::Name instance" do
24
- Draper::Base.model_name.should be_instance_of(ActiveModel::Name)
25
- end
26
- end
27
-
28
36
  context(".decorates") do
29
37
  it "sets the model class for the decorator" do
30
38
  ProductDecorator.new(source).model_class.should == Product
@@ -0,0 +1,5 @@
1
+ class Decorator < Draper::Base
2
+ def self.own_class_method
3
+ "own class method"
4
+ end
5
+ end
@@ -3,6 +3,10 @@ class Product < ActiveRecord::Base
3
3
  return Product.new
4
4
  end
5
5
 
6
+ def self.sample_class_method
7
+ "sample class method"
8
+ end
9
+
6
10
  def hello_world
7
11
  "Hello, World"
8
12
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: draper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.8.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-10-08 00:00:00.000000000Z
12
+ date: 2011-10-09 00:00:00.000000000Z
13
13
  dependencies: []
14
14
  description: Draper reimagines the role of helpers in the view layer of a Rails application,
15
15
  allowing an object-oriented approach rather than procedural.
@@ -66,6 +66,7 @@ files:
66
66
  - spec/samples/active_record.rb
67
67
  - spec/samples/application_controller.rb
68
68
  - spec/samples/application_helper.rb
69
+ - spec/samples/decorator.rb
69
70
  - spec/samples/decorator_with_allows.rb
70
71
  - spec/samples/decorator_with_application_helper.rb
71
72
  - spec/samples/decorator_with_denies.rb
@@ -104,6 +105,7 @@ test_files:
104
105
  - spec/samples/active_record.rb
105
106
  - spec/samples/application_controller.rb
106
107
  - spec/samples/application_helper.rb
108
+ - spec/samples/decorator.rb
107
109
  - spec/samples/decorator_with_allows.rb
108
110
  - spec/samples/decorator_with_application_helper.rb
109
111
  - spec/samples/decorator_with_denies.rb