view_models 2.0.1 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.bundle/config +2 -0
- data/.gitignore +8 -0
- data/.rspec +2 -0
- data/.rvmrc +1 -0
- data/.travis.yml +19 -0
- data/.yardoc/checksums +13 -0
- data/.yardoc/object_types +0 -0
- data/.yardoc/objects/root.dat +0 -0
- data/.yardoc/proxy_types +0 -0
- data/Appraisals +15 -0
- data/CHANGELOG +31 -0
- data/Gemfile +13 -0
- data/Gemfile.lock +174 -0
- data/MIT-LICENSE +20 -0
- data/README.textile +199 -0
- data/Rakefile +24 -0
- data/doc/ModulesInRenderHierarchy.html +186 -0
- data/doc/ModulesInRenderHierarchy/ClassMethods.html +188 -0
- data/doc/ViewModels.html +202 -0
- data/doc/ViewModels/Base.html +1342 -0
- data/doc/ViewModels/ContextExtractor.html +406 -0
- data/doc/ViewModels/Extensions.html +128 -0
- data/doc/ViewModels/Extensions/ModelReader.html +255 -0
- data/doc/ViewModels/Extensions/ModelReader/FilteredDelegationInstaller.html +908 -0
- data/doc/ViewModels/Extensions/ModelReader/Options.html +551 -0
- data/doc/ViewModels/Extensions/View.html +303 -0
- data/doc/ViewModels/Helpers.html +129 -0
- data/doc/ViewModels/Helpers/Mapping.html +562 -0
- data/doc/ViewModels/Helpers/Mapping/Collection.html +844 -0
- data/doc/ViewModels/Helpers/View.html +287 -0
- data/doc/ViewModels/PathStore.html +745 -0
- data/doc/ViewModels/RenderOptions.html +126 -0
- data/doc/ViewModels/RenderOptions/Base.html +1187 -0
- data/doc/ViewModels/RenderOptions/Partial.html +231 -0
- data/doc/ViewModels/RenderOptions/Template.html +231 -0
- data/doc/ViewModels/View.html +414 -0
- data/doc/ViewModelsGenerator.html +410 -0
- data/doc/_index.html +317 -0
- data/doc/class_list.html +53 -0
- data/doc/css/common.css +1 -0
- data/doc/css/full_list.css +57 -0
- data/doc/css/style.css +328 -0
- data/doc/file.README.html +113 -0
- data/doc/file_list.html +55 -0
- data/doc/frames.html +28 -0
- data/doc/index.html +113 -0
- data/doc/js/app.js +214 -0
- data/doc/js/full_list.js +173 -0
- data/doc/js/jquery.js +4 -0
- data/doc/method_list.html +628 -0
- data/doc/top-level-namespace.html +114 -0
- data/feature_support/testapp/app/controllers/heroes_controller.rb +6 -0
- data/feature_support/testapp/app/controllers/users_controller.rb +6 -0
- data/feature_support/testapp/app/helpers/application_helper.rb +8 -0
- data/feature_support/testapp/app/models/hero.rb +8 -0
- data/feature_support/testapp/app/models/user.rb +3 -0
- data/feature_support/testapp/app/view_models/hero.rb +8 -0
- data/feature_support/testapp/app/view_models/test.rb +8 -0
- data/feature_support/testapp/app/view_models/user.rb +14 -0
- data/feature_support/testapp/app/views/heroes/show.html.slim +6 -0
- data/feature_support/testapp/app/views/users/_box.html.slim +8 -0
- data/feature_support/testapp/app/views/users/show.html.slim +6 -0
- data/feature_support/testapp/config/application.rb +64 -0
- data/feature_support/testapp/config/cucumber.yml +8 -0
- data/feature_support/testapp/config/database.yml +28 -0
- data/feature_support/testapp/config/environments/cucumber.rb +11 -0
- data/feature_support/testapp/config/environments/test.rb +27 -0
- data/feature_support/testapp/config/routes.rb +4 -0
- data/feature_support/testapp/db/migrate/1_create_users.rb +13 -0
- data/feature_support/testapp/features/inheritance.feature +16 -0
- data/feature_support/testapp/features/step_definitions/testapp_steps.rb +16 -0
- data/feature_support/testapp/features/support/env.rb +13 -0
- data/feature_support/testapp/features/users.feature +15 -0
- data/feature_support/testapp/lib/tasks/cucumber.rake +31 -0
- data/feature_support/testapp/spec/factories/heroes.rb +7 -0
- data/feature_support/testapp/spec/factories/users.rb +7 -0
- data/features/rails_integration.feature +21 -0
- data/features/step_definitions/rails_steps.rb +112 -0
- data/features/support/env.rb +6 -0
- data/gemfiles/3.0.Gemfile +13 -0
- data/gemfiles/3.1.Gemfile +15 -0
- data/gemfiles/3.2.gemfile +15 -0
- data/lib/rails/generators/view_models/USAGE +6 -0
- data/lib/rails/generators/view_models/templates/views/_collection.html.erb +6 -0
- data/lib/{rails2/generators/view_models/templates/views/view_models/collection → rails/generators/view_models/templates/views}/_collection.html.haml +1 -2
- data/lib/rails/generators/view_models/templates/views/_collection.html.slim +6 -0
- data/lib/{rails2/generators/view_models/templates/views/_empty.html.haml → rails/generators/view_models/templates/views/_empty.html.erb} +0 -0
- data/lib/rails/generators/view_models/templates/views/_empty.html.haml +0 -0
- data/lib/rails/generators/view_models/templates/views/_empty.html.slim +0 -0
- data/lib/rails/generators/view_models/templates/views/_list.html.erb +6 -0
- data/lib/rails/generators/view_models/templates/views/_list.html.haml +4 -0
- data/lib/rails/generators/view_models/templates/views/_list.html.slim +5 -0
- data/lib/rails/generators/view_models/templates/views/_pagination.html.erb +18 -0
- data/lib/{rails2/generators/view_models/templates/views/view_models/collection → rails/generators/view_models/templates/views}/_pagination.html.haml +2 -2
- data/lib/rails/generators/view_models/templates/views/_pagination.html.slim +12 -0
- data/lib/rails/generators/view_models/templates/views/_table.html.erb +10 -0
- data/lib/{rails2/generators/view_models/templates/views/view_models/collection → rails/generators/view_models/templates/views}/_table.html.haml +0 -0
- data/lib/rails/generators/view_models/templates/views/_table.html.slim +5 -0
- data/lib/rails/generators/view_models/view_models_generator.rb +57 -0
- data/lib/view_models.rb +15 -5
- data/lib/{shared/lib/view_models → view_models}/base.rb +148 -37
- data/lib/{shared/lib/view_models → view_models}/context_extractor.rb +6 -2
- data/lib/{shared/lib/view_models → view_models}/extensions/model_reader.rb +27 -13
- data/lib/{rails2/lib → view_models}/extensions/view.rb +6 -1
- data/lib/view_models/helpers/collection.rb +113 -0
- data/lib/{shared/lib/view_models → view_models}/helpers/mapping.rb +12 -15
- data/lib/{rails2/lib → view_models}/helpers/view.rb +5 -1
- data/lib/{shared/lib/view_models → view_models}/path_store.rb +6 -1
- data/lib/{shared/lib/view_models → view_models}/render_options.rb +19 -4
- data/lib/view_models/version.rb +5 -0
- data/lib/{rails2/lib/view_models → view_models}/view.rb +7 -6
- data/spec/{rails2/lib → lib}/view_models/base_spec.rb +38 -5
- data/spec/{rails2/lib → lib/view_models}/extensions/model_reader_spec.rb +4 -4
- data/spec/{shared/lib → lib/view_models}/helpers/collection_spec.rb +21 -1
- data/spec/{shared/lib → lib/view_models}/helpers/mapping_spec.rb +6 -5
- data/spec/{rails2/lib → lib/view_models}/helpers/view_spec.rb +1 -1
- data/spec/lib/view_models/view_spec.rb +42 -0
- data/spec/spec_helper.rb +32 -0
- data/spec/spec_helper_extensions.rb +13 -0
- data/view_models.gemspec +36 -0
- metadata +411 -142
- data/lib/init.rb +0 -1
- data/lib/padrino/README.textile +0 -3
- data/lib/padrino/init.rb +0 -10
- data/lib/padrino/lib/helpers/collection.rb +0 -27
- data/lib/padrino/lib/padrino/view_models.rb +0 -19
- data/lib/padrino/lib/view_models/base.rb +0 -65
- data/lib/rails2/README.textile +0 -3
- data/lib/rails2/TODO.textile +0 -5
- data/lib/rails2/generators/view_models/USAGE +0 -6
- data/lib/rails2/generators/view_models/templates/README +0 -1
- data/lib/rails2/generators/view_models/templates/spec/view_model_spec.rb +0 -7
- data/lib/rails2/generators/view_models/templates/view_models/view_model.rb +0 -5
- data/lib/rails2/generators/view_models/templates/views/view_models/collection/_collection.html.erb +0 -1
- data/lib/rails2/generators/view_models/templates/views/view_models/collection/_collection.text.erb +0 -6
- data/lib/rails2/generators/view_models/templates/views/view_models/collection/_list.html.erb +0 -1
- data/lib/rails2/generators/view_models/templates/views/view_models/collection/_list.text.erb +0 -6
- data/lib/rails2/generators/view_models/templates/views/view_models/collection/_pagination.text.erb +0 -3
- data/lib/rails2/generators/view_models/templates/views/view_models/collection/_table.text.erb +0 -10
- data/lib/rails2/generators/view_models/view_models_generator.rb +0 -47
- data/lib/rails2/init.rb +0 -18
- data/lib/rails2/lib/experimental/README.textile +0 -32
- data/lib/rails2/lib/experimental/modules_in_render_hierarchy.rb +0 -21
- data/lib/rails2/lib/helpers/collection.rb +0 -27
- data/lib/rails2/lib/view_models.rb +0 -1
- data/lib/rails2/lib/view_models/base.rb +0 -99
- data/lib/shared/README.textile +0 -3
- data/lib/shared/init.rb +0 -11
- data/lib/shared/lib/view_models.rb +0 -4
- data/lib/shared/lib/view_models/extensions/active_record.rb +0 -27
- data/lib/shared/lib/view_models/helpers/collection.rb +0 -110
- data/spec/padrino/integration/integration_spec.rb +0 -287
- data/spec/padrino/lib/helpers/collection_spec.rb +0 -30
- data/spec/rails2/integration/integration_spec.rb +0 -279
- data/spec/rails2/lib/extensions/active_record_spec.rb +0 -31
- data/spec/rails2/lib/helpers/collection_spec.rb +0 -30
- data/spec/rails2/lib/view_models/view_spec.rb +0 -12
@@ -1,30 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), '../../spec_helper')
|
2
|
-
|
3
|
-
describe ViewModels::Helpers::Mapping::Collection do
|
4
|
-
include ViewModels::Helpers::Mapping
|
5
|
-
|
6
|
-
before(:each) do
|
7
|
-
@collection = stub :collection
|
8
|
-
@context = stub :context
|
9
|
-
@collection_view_model = ViewModels::Helpers::Mapping::Collection.new @collection, @context
|
10
|
-
end
|
11
|
-
|
12
|
-
describe "render_partial" do
|
13
|
-
it "should call instance eval on the context" do
|
14
|
-
@context.should_receive(:instance_eval).once
|
15
|
-
|
16
|
-
@collection_view_model.send :render_partial, :some_name, :some_params
|
17
|
-
end
|
18
|
-
it "should render the partial in the 'context' context" do
|
19
|
-
@context.should_receive(:render).once
|
20
|
-
|
21
|
-
@collection_view_model.send :render_partial, :some_name, :some_params
|
22
|
-
end
|
23
|
-
it "should call render partial on context with the passed through parameters" do
|
24
|
-
@context.should_receive(:render).once.with('view_models/collection/_some_name', :locals => { :a => :b })
|
25
|
-
|
26
|
-
@collection_view_model.send :render_partial, :some_name, { :a => :b }
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
end
|
@@ -1,279 +0,0 @@
|
|
1
|
-
this = File.dirname(__FILE__)
|
2
|
-
|
3
|
-
require File.join(this, '/../spec_helper')
|
4
|
-
|
5
|
-
require File.join(this, 'models/subclass')
|
6
|
-
require File.join(this, 'models/sub_subclass')
|
7
|
-
|
8
|
-
require File.join(this, 'view_models/project')
|
9
|
-
require File.join(this, 'view_models/subclass')
|
10
|
-
require File.join(this, 'view_models/sub_subclass')
|
11
|
-
require File.join(this, 'view_models/module_for_rendering')
|
12
|
-
|
13
|
-
require 'action_controller'
|
14
|
-
require 'action_controller/test_process'
|
15
|
-
|
16
|
-
class TestController < ActionController::Base; end
|
17
|
-
|
18
|
-
ActionView::Base.send :include, ViewModels::Helpers::Mapping
|
19
|
-
|
20
|
-
describe 'Integration' do
|
21
|
-
|
22
|
-
before(:each) do
|
23
|
-
begin
|
24
|
-
@controller = TestController.new
|
25
|
-
@controller.class.view_paths = ['spec/rails2/integration/views']
|
26
|
-
|
27
|
-
@logger = stub :logger, :null_object => true
|
28
|
-
@controller.logger = @logger
|
29
|
-
|
30
|
-
@request = ActionController::TestRequest.new
|
31
|
-
@response = ActionController::TestResponse.new
|
32
|
-
@controller.request = @request
|
33
|
-
@controller.response = @response
|
34
|
-
|
35
|
-
# TODO Make separate contexts, one where the controller has rendered, one where it has not.
|
36
|
-
#
|
37
|
-
# Let the Controller generate a view instance.
|
38
|
-
#
|
39
|
-
# @controller.process @request, @response
|
40
|
-
|
41
|
-
@view = ActionView::Base.new @controller.class.view_paths, {}, @controller
|
42
|
-
@model = SubSubclass.new
|
43
|
-
@model.id = :some_id
|
44
|
-
@view_model = ViewModels::SubSubclass.new @model, @view
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
before(:all) { puts "\n#{self.send(:description_args)[0]}:" }
|
49
|
-
|
50
|
-
# context 'experimental inclusion of module in render hierarchy' do
|
51
|
-
# before(:each) do
|
52
|
-
# ViewModels::Base.send :include, ModulesInRenderHierarchy
|
53
|
-
# @view_model.class.send :include, ModuleForRendering
|
54
|
-
# end
|
55
|
-
# describe 'render_as' do
|
56
|
-
# it 'should description' do
|
57
|
-
# @view_model.render_as(:not_found_in_sub_subclass_but_in_module).should == '_not_found_in_sub_subclass_but_in_module.erb'
|
58
|
-
# end
|
59
|
-
# end
|
60
|
-
# end
|
61
|
-
|
62
|
-
describe 'ActiveRecord Extensions' do
|
63
|
-
before(:each) do
|
64
|
-
@view_model.extend ViewModels::Extensions::ActiveRecord
|
65
|
-
end
|
66
|
-
it 'should delegate the id' do
|
67
|
-
@view_model.id.should == :some_id
|
68
|
-
end
|
69
|
-
it 'should delegate the id' do
|
70
|
-
@view_model.dom_id.should == 'sub_subclass_some_id'
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
describe 'view_model_for' do
|
75
|
-
context 'view model' do
|
76
|
-
it 'should be available' do
|
77
|
-
lambda { @view_model.view_model_for @model }.should_not raise_error
|
78
|
-
end
|
79
|
-
it 'should return the right one' do
|
80
|
-
@view_model.view_model_for(@model).should be_kind_of(ViewModels::SubSubclass)
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
84
|
-
describe 'view_model_class_for' do
|
85
|
-
context 'view model' do
|
86
|
-
it 'should be available' do
|
87
|
-
lambda { @view_model.view_model_class_for @model }.should_not raise_error
|
88
|
-
end
|
89
|
-
it 'should return the right class' do
|
90
|
-
@view_model.view_model_class_for(@model).should == ViewModels::SubSubclass
|
91
|
-
end
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
describe 'capture in view model method' do
|
96
|
-
context 'template' do
|
97
|
-
it 'should capture the content of the block' do
|
98
|
-
@view_model.render_as(:capture_in_template).should == 'Capturing: A Pirate!'
|
99
|
-
end
|
100
|
-
end
|
101
|
-
context 'in view model' do
|
102
|
-
it 'should capture the content of the block' do
|
103
|
-
@view_model.render_as(:capture_in_view_model).should == 'Capturing: A Pirate!'
|
104
|
-
end
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
describe 'controller context' do
|
109
|
-
it 'should work' do
|
110
|
-
controller = ActionController::Base.new
|
111
|
-
|
112
|
-
lambda {
|
113
|
-
ViewModels::SubSubclass.new @model, controller
|
114
|
-
}.should_not raise_error
|
115
|
-
end
|
116
|
-
end
|
117
|
-
|
118
|
-
describe 'view_model_for inclusion in view' do
|
119
|
-
it 'should be included' do
|
120
|
-
view = ActionView::Base.new
|
121
|
-
|
122
|
-
lambda {
|
123
|
-
view.view_model_for @model
|
124
|
-
}.should_not raise_error
|
125
|
-
end
|
126
|
-
end
|
127
|
-
|
128
|
-
describe 'collection rendering' do
|
129
|
-
context 'default format' do
|
130
|
-
it 'should render a html list' do
|
131
|
-
@view_model.render_as(:list_example).should == "<ol class=\"collection\"><li>_list_item.html.erb</li><li>_list_item.html.erb</li></ol>"
|
132
|
-
end
|
133
|
-
it 'should render a html collection' do
|
134
|
-
@view_model.render_as(:collection_example).should == "<ul class=\"collection\"><li>_collection_item.html.erb</li><li>_collection_item.html.erb</li></ul>"
|
135
|
-
end
|
136
|
-
end
|
137
|
-
context 'format html' do
|
138
|
-
it 'should render a html list' do
|
139
|
-
@view_model.render_as(:list_example, :format => :html).should == "<ol class=\"collection\"><li>_list_item.html.erb</li><li>_list_item.html.erb</li></ol>"
|
140
|
-
end
|
141
|
-
it 'should render a html collection' do
|
142
|
-
@view_model.render_as(:collection_example, :format => :html).should == "<ul class=\"collection\"><li>_collection_item.html.erb</li><li>_collection_item.html.erb</li></ul>"
|
143
|
-
end
|
144
|
-
end
|
145
|
-
context 'format text' do
|
146
|
-
it 'should render a text list' do
|
147
|
-
@view_model.render_as(:list_example, :format => :text).should == '_list_item.text.erb\n_list_item.text.erb'
|
148
|
-
end
|
149
|
-
it 'should render a text collection' do
|
150
|
-
@view_model.render_as(:collection_example, :format => :text).should == '_collection_item.text.erb_collection_item.text.erb'
|
151
|
-
end
|
152
|
-
end
|
153
|
-
end
|
154
|
-
|
155
|
-
describe 'model attributes' do
|
156
|
-
it 'should pass through unfiltered attributes' do
|
157
|
-
@view_model.some_untouched_attribute.should == :some_value
|
158
|
-
end
|
159
|
-
it 'should filter some attributes' do
|
160
|
-
@view_model.some_filtered_attribute.should == '%3Cscript%3Efilter+me%3C%2Fscript%3E'
|
161
|
-
end
|
162
|
-
it 'should filter some attributes multiple times' do
|
163
|
-
@view_model.some_doubly_doubled_attribute.should == 'blahblahblahblah'
|
164
|
-
end
|
165
|
-
it 'should filter some attributes multiple times correctly' do
|
166
|
-
@view_model.some_mangled_attribute.should == 'DCBDCB'
|
167
|
-
end
|
168
|
-
end
|
169
|
-
|
170
|
-
describe 'controller_method' do
|
171
|
-
it 'should delegate to the context' do
|
172
|
-
@view_model.logger.should == @logger
|
173
|
-
end
|
174
|
-
end
|
175
|
-
|
176
|
-
describe "render_template" do
|
177
|
-
it "should render the right template" do
|
178
|
-
@view_model.render_template(:show).should == 'show.html.erb'
|
179
|
-
end
|
180
|
-
it "should render the right template with format" do
|
181
|
-
@view_model.render_template(:show, :format => :text).should == 'show.text.erb'
|
182
|
-
end
|
183
|
-
end
|
184
|
-
|
185
|
-
describe 'render_as' do
|
186
|
-
describe 'render_the alias' do
|
187
|
-
it 'should also render' do
|
188
|
-
@view_model.render_the(:part_that_is_dependent_on_the_view_model).should == '_part_that_is_dependent_on_the_view_model.erb'
|
189
|
-
end
|
190
|
-
end
|
191
|
-
describe "explicit partial rendering" do
|
192
|
-
it "should render the right partial" do
|
193
|
-
# If one wants explicit template rendering, he needs to work more.
|
194
|
-
# Let's be opinionated here :)
|
195
|
-
#
|
196
|
-
@view_model.render_as(:partial => 'view_models/sub_subclass/inner', :format => :nesting).should == '_inner.nesting.erb'
|
197
|
-
end
|
198
|
-
end
|
199
|
-
describe "nesting" do
|
200
|
-
it "should render the right nested template, with an explicitly defined format (see template)" do
|
201
|
-
@view_model.render_as(:outer, :format => :explicit).should == '_inner.also_explicit.erb'
|
202
|
-
end
|
203
|
-
it "should render the right nested template, respecting the already defined format" do
|
204
|
-
@view_model.render_as(:outer, :format => :nesting).should == '_inner.nesting.erb'
|
205
|
-
end
|
206
|
-
end
|
207
|
-
describe 'template inheritance' do
|
208
|
-
it 'should raise ViewModels::MissingTemplateError if template is not found' do
|
209
|
-
lambda { @view_model.render_as(:this_template_does_not_exist_at_allllll) }.should raise_error(ViewModels::MissingTemplateError, "No template '_this_template_does_not_exist_at_allllll' with default format found.")
|
210
|
-
end
|
211
|
-
it 'should raise ViewModels::MissingTemplateError if template is not found, with specific path' do
|
212
|
-
lambda { @view_model.render_as(:partial => 'view_models/sub_subclass/this_template_does_not_exist_at_allllll') }.should raise_error(ViewModels::MissingTemplateError, "No template 'view_models/sub_subclass/_this_template_does_not_exist_at_allllll' with default format found.")
|
213
|
-
end
|
214
|
-
it 'should raise ViewModels::MissingTemplateError if template is not found, with format' do
|
215
|
-
lambda { @view_model.render_as(:this_template_does_not_exist_at_allllll, :format => :gaga) }.should raise_error(ViewModels::MissingTemplateError, "No template '_this_template_does_not_exist_at_allllll' with format gaga found.")
|
216
|
-
end
|
217
|
-
it "should use its own template" do
|
218
|
-
@view_model.render_as(:exists).should == '_exists.html.erb' # The default
|
219
|
-
end
|
220
|
-
it "should use the subclass' template" do
|
221
|
-
@view_model.render_as(:no_sub_subclass).should == '_no_sub_subclass.erb'
|
222
|
-
end
|
223
|
-
end
|
224
|
-
describe 'format' do
|
225
|
-
it 'should render html' do
|
226
|
-
@view_model.render_as(:exists, :format => nil).should == '_exists.html.erb' # the default
|
227
|
-
end
|
228
|
-
it 'should render erb' do
|
229
|
-
@view_model.render_as(:exists, :format => '').should == '_exists.erb'
|
230
|
-
end
|
231
|
-
it 'should render text' do
|
232
|
-
@view_model.render_as(:exists, :format => :text).should == '_exists.text.erb'
|
233
|
-
end
|
234
|
-
it 'should render html' do
|
235
|
-
@view_model.render_as(:exists, :format => :html).should == '_exists.html.erb'
|
236
|
-
end
|
237
|
-
end
|
238
|
-
describe 'locals' do
|
239
|
-
it 'should render html' do
|
240
|
-
@view_model.render_as(:exists, :locals => { :local_name => :some_local }).should == '_exists.html.erb with some_local'
|
241
|
-
end
|
242
|
-
it 'should render html' do
|
243
|
-
@view_model.render_as(:exists, :format => nil, :locals => { :local_name => :some_local }).should == '_exists.html.erb with some_local'
|
244
|
-
end
|
245
|
-
it 'should render text' do
|
246
|
-
@view_model.render_as(:exists, :format => '', :locals => { :local_name => :some_local }).should == '_exists.erb with some_local'
|
247
|
-
end
|
248
|
-
it 'should render text' do
|
249
|
-
@view_model.render_as(:exists, :format => :text, :locals => { :local_name => :some_local }).should == '_exists.text.erb with some_local'
|
250
|
-
end
|
251
|
-
it 'should render html' do
|
252
|
-
@view_model.render_as(:exists, :format => :html, :locals => { :local_name => :some_local }).should == '_exists.html.erb with some_local'
|
253
|
-
end
|
254
|
-
end
|
255
|
-
describe 'memoizing' do
|
256
|
-
it 'should memoize and not generate always a new path' do
|
257
|
-
@view_model.class.should_receive(:generate_template_path_from).once.and_return "view_models/sub_subclass/_not_found_in_sub_subclass"
|
258
|
-
|
259
|
-
@view_model.render_as :not_found_in_sub_subclass
|
260
|
-
@view_model.render_as :not_found_in_sub_subclass
|
261
|
-
@view_model.render_as :not_found_in_sub_subclass
|
262
|
-
@view_model.render_as :not_found_in_sub_subclass
|
263
|
-
@view_model.render_as :not_found_in_sub_subclass
|
264
|
-
end
|
265
|
-
it 'should render the right one' do
|
266
|
-
@view_model.render_as :exists_in_both
|
267
|
-
@view_model.render_as(:exists_in_both).should == 'in sub subclass'
|
268
|
-
|
269
|
-
other_view_model = ViewModels::Subclass.new Subclass.new, @view
|
270
|
-
other_view_model.render_as :exists_in_both
|
271
|
-
other_view_model.render_as(:exists_in_both).should == 'in subclass'
|
272
|
-
|
273
|
-
@view_model.render_as :exists_in_both
|
274
|
-
@view_model.render_as(:exists_in_both).should == 'in sub subclass'
|
275
|
-
end
|
276
|
-
end
|
277
|
-
end
|
278
|
-
|
279
|
-
end
|
@@ -1,31 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), '/../../spec_helper')
|
2
|
-
|
3
|
-
describe ViewModels::Extensions::ActiveRecord do
|
4
|
-
|
5
|
-
describe "to_param" do
|
6
|
-
before(:each) do
|
7
|
-
@model = stub :model
|
8
|
-
@view_model = ViewModels::Base.new @model, nil
|
9
|
-
@view_model.extend ViewModels::Extensions::ActiveRecord
|
10
|
-
end
|
11
|
-
it "should delegate to_param to the model" do
|
12
|
-
@model.should_receive(:to_param).once
|
13
|
-
|
14
|
-
@view_model.to_param
|
15
|
-
end
|
16
|
-
|
17
|
-
it "should delegate id to the model" do
|
18
|
-
@model.should_receive(:id).once
|
19
|
-
|
20
|
-
@view_model.id
|
21
|
-
end
|
22
|
-
|
23
|
-
it "should delegate dom_id to ActionController::RecordIdentifier" do
|
24
|
-
ActionController::RecordIdentifier.should_receive(:dom_id).once
|
25
|
-
|
26
|
-
@view_model.dom_id
|
27
|
-
end
|
28
|
-
|
29
|
-
end
|
30
|
-
|
31
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), '/../../spec_helper')
|
2
|
-
|
3
|
-
describe ViewModels::Helpers::Mapping::Collection do
|
4
|
-
include ViewModels::Helpers::Mapping
|
5
|
-
|
6
|
-
before(:each) do
|
7
|
-
@collection = stub :collection
|
8
|
-
@context = stub :context
|
9
|
-
@collection_view_model = ViewModels::Helpers::Mapping::Collection.new @collection, @context
|
10
|
-
end
|
11
|
-
|
12
|
-
describe "render_partial" do
|
13
|
-
it "should call instance eval on the context" do
|
14
|
-
@context.should_receive(:instance_eval).once
|
15
|
-
|
16
|
-
@collection_view_model.send :render_partial, :some_name, :some_params
|
17
|
-
end
|
18
|
-
it "should render the partial in the 'context' context" do
|
19
|
-
@context.should_receive(:render).once
|
20
|
-
|
21
|
-
@collection_view_model.send :render_partial, :some_name, :some_params
|
22
|
-
end
|
23
|
-
it "should call render partial on context with the passed through parameters" do
|
24
|
-
@context.should_receive(:render).once.with(:partial => 'view_models/collection/some_name', :locals => { :a => :b })
|
25
|
-
|
26
|
-
@collection_view_model.send :render_partial, :some_name, { :a => :b }
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
end
|
@@ -1,12 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), '/../../spec_helper')
|
2
|
-
|
3
|
-
describe ViewModels::View do
|
4
|
-
|
5
|
-
it "should be initializable" do
|
6
|
-
controller_class = stub :controller_class, :view_paths => ActionView::PathSet.new
|
7
|
-
controller = stub :controller, :class => controller_class
|
8
|
-
|
9
|
-
ViewModels::View.new controller, Module.new
|
10
|
-
end
|
11
|
-
|
12
|
-
end
|