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.
Files changed (157) hide show
  1. data/.bundle/config +2 -0
  2. data/.gitignore +8 -0
  3. data/.rspec +2 -0
  4. data/.rvmrc +1 -0
  5. data/.travis.yml +19 -0
  6. data/.yardoc/checksums +13 -0
  7. data/.yardoc/object_types +0 -0
  8. data/.yardoc/objects/root.dat +0 -0
  9. data/.yardoc/proxy_types +0 -0
  10. data/Appraisals +15 -0
  11. data/CHANGELOG +31 -0
  12. data/Gemfile +13 -0
  13. data/Gemfile.lock +174 -0
  14. data/MIT-LICENSE +20 -0
  15. data/README.textile +199 -0
  16. data/Rakefile +24 -0
  17. data/doc/ModulesInRenderHierarchy.html +186 -0
  18. data/doc/ModulesInRenderHierarchy/ClassMethods.html +188 -0
  19. data/doc/ViewModels.html +202 -0
  20. data/doc/ViewModels/Base.html +1342 -0
  21. data/doc/ViewModels/ContextExtractor.html +406 -0
  22. data/doc/ViewModels/Extensions.html +128 -0
  23. data/doc/ViewModels/Extensions/ModelReader.html +255 -0
  24. data/doc/ViewModels/Extensions/ModelReader/FilteredDelegationInstaller.html +908 -0
  25. data/doc/ViewModels/Extensions/ModelReader/Options.html +551 -0
  26. data/doc/ViewModels/Extensions/View.html +303 -0
  27. data/doc/ViewModels/Helpers.html +129 -0
  28. data/doc/ViewModels/Helpers/Mapping.html +562 -0
  29. data/doc/ViewModels/Helpers/Mapping/Collection.html +844 -0
  30. data/doc/ViewModels/Helpers/View.html +287 -0
  31. data/doc/ViewModels/PathStore.html +745 -0
  32. data/doc/ViewModels/RenderOptions.html +126 -0
  33. data/doc/ViewModels/RenderOptions/Base.html +1187 -0
  34. data/doc/ViewModels/RenderOptions/Partial.html +231 -0
  35. data/doc/ViewModels/RenderOptions/Template.html +231 -0
  36. data/doc/ViewModels/View.html +414 -0
  37. data/doc/ViewModelsGenerator.html +410 -0
  38. data/doc/_index.html +317 -0
  39. data/doc/class_list.html +53 -0
  40. data/doc/css/common.css +1 -0
  41. data/doc/css/full_list.css +57 -0
  42. data/doc/css/style.css +328 -0
  43. data/doc/file.README.html +113 -0
  44. data/doc/file_list.html +55 -0
  45. data/doc/frames.html +28 -0
  46. data/doc/index.html +113 -0
  47. data/doc/js/app.js +214 -0
  48. data/doc/js/full_list.js +173 -0
  49. data/doc/js/jquery.js +4 -0
  50. data/doc/method_list.html +628 -0
  51. data/doc/top-level-namespace.html +114 -0
  52. data/feature_support/testapp/app/controllers/heroes_controller.rb +6 -0
  53. data/feature_support/testapp/app/controllers/users_controller.rb +6 -0
  54. data/feature_support/testapp/app/helpers/application_helper.rb +8 -0
  55. data/feature_support/testapp/app/models/hero.rb +8 -0
  56. data/feature_support/testapp/app/models/user.rb +3 -0
  57. data/feature_support/testapp/app/view_models/hero.rb +8 -0
  58. data/feature_support/testapp/app/view_models/test.rb +8 -0
  59. data/feature_support/testapp/app/view_models/user.rb +14 -0
  60. data/feature_support/testapp/app/views/heroes/show.html.slim +6 -0
  61. data/feature_support/testapp/app/views/users/_box.html.slim +8 -0
  62. data/feature_support/testapp/app/views/users/show.html.slim +6 -0
  63. data/feature_support/testapp/config/application.rb +64 -0
  64. data/feature_support/testapp/config/cucumber.yml +8 -0
  65. data/feature_support/testapp/config/database.yml +28 -0
  66. data/feature_support/testapp/config/environments/cucumber.rb +11 -0
  67. data/feature_support/testapp/config/environments/test.rb +27 -0
  68. data/feature_support/testapp/config/routes.rb +4 -0
  69. data/feature_support/testapp/db/migrate/1_create_users.rb +13 -0
  70. data/feature_support/testapp/features/inheritance.feature +16 -0
  71. data/feature_support/testapp/features/step_definitions/testapp_steps.rb +16 -0
  72. data/feature_support/testapp/features/support/env.rb +13 -0
  73. data/feature_support/testapp/features/users.feature +15 -0
  74. data/feature_support/testapp/lib/tasks/cucumber.rake +31 -0
  75. data/feature_support/testapp/spec/factories/heroes.rb +7 -0
  76. data/feature_support/testapp/spec/factories/users.rb +7 -0
  77. data/features/rails_integration.feature +21 -0
  78. data/features/step_definitions/rails_steps.rb +112 -0
  79. data/features/support/env.rb +6 -0
  80. data/gemfiles/3.0.Gemfile +13 -0
  81. data/gemfiles/3.1.Gemfile +15 -0
  82. data/gemfiles/3.2.gemfile +15 -0
  83. data/lib/rails/generators/view_models/USAGE +6 -0
  84. data/lib/rails/generators/view_models/templates/views/_collection.html.erb +6 -0
  85. data/lib/{rails2/generators/view_models/templates/views/view_models/collection → rails/generators/view_models/templates/views}/_collection.html.haml +1 -2
  86. data/lib/rails/generators/view_models/templates/views/_collection.html.slim +6 -0
  87. data/lib/{rails2/generators/view_models/templates/views/_empty.html.haml → rails/generators/view_models/templates/views/_empty.html.erb} +0 -0
  88. data/lib/rails/generators/view_models/templates/views/_empty.html.haml +0 -0
  89. data/lib/rails/generators/view_models/templates/views/_empty.html.slim +0 -0
  90. data/lib/rails/generators/view_models/templates/views/_list.html.erb +6 -0
  91. data/lib/rails/generators/view_models/templates/views/_list.html.haml +4 -0
  92. data/lib/rails/generators/view_models/templates/views/_list.html.slim +5 -0
  93. data/lib/rails/generators/view_models/templates/views/_pagination.html.erb +18 -0
  94. data/lib/{rails2/generators/view_models/templates/views/view_models/collection → rails/generators/view_models/templates/views}/_pagination.html.haml +2 -2
  95. data/lib/rails/generators/view_models/templates/views/_pagination.html.slim +12 -0
  96. data/lib/rails/generators/view_models/templates/views/_table.html.erb +10 -0
  97. data/lib/{rails2/generators/view_models/templates/views/view_models/collection → rails/generators/view_models/templates/views}/_table.html.haml +0 -0
  98. data/lib/rails/generators/view_models/templates/views/_table.html.slim +5 -0
  99. data/lib/rails/generators/view_models/view_models_generator.rb +57 -0
  100. data/lib/view_models.rb +15 -5
  101. data/lib/{shared/lib/view_models → view_models}/base.rb +148 -37
  102. data/lib/{shared/lib/view_models → view_models}/context_extractor.rb +6 -2
  103. data/lib/{shared/lib/view_models → view_models}/extensions/model_reader.rb +27 -13
  104. data/lib/{rails2/lib → view_models}/extensions/view.rb +6 -1
  105. data/lib/view_models/helpers/collection.rb +113 -0
  106. data/lib/{shared/lib/view_models → view_models}/helpers/mapping.rb +12 -15
  107. data/lib/{rails2/lib → view_models}/helpers/view.rb +5 -1
  108. data/lib/{shared/lib/view_models → view_models}/path_store.rb +6 -1
  109. data/lib/{shared/lib/view_models → view_models}/render_options.rb +19 -4
  110. data/lib/view_models/version.rb +5 -0
  111. data/lib/{rails2/lib/view_models → view_models}/view.rb +7 -6
  112. data/spec/{rails2/lib → lib}/view_models/base_spec.rb +38 -5
  113. data/spec/{rails2/lib → lib/view_models}/extensions/model_reader_spec.rb +4 -4
  114. data/spec/{shared/lib → lib/view_models}/helpers/collection_spec.rb +21 -1
  115. data/spec/{shared/lib → lib/view_models}/helpers/mapping_spec.rb +6 -5
  116. data/spec/{rails2/lib → lib/view_models}/helpers/view_spec.rb +1 -1
  117. data/spec/lib/view_models/view_spec.rb +42 -0
  118. data/spec/spec_helper.rb +32 -0
  119. data/spec/spec_helper_extensions.rb +13 -0
  120. data/view_models.gemspec +36 -0
  121. metadata +411 -142
  122. data/lib/init.rb +0 -1
  123. data/lib/padrino/README.textile +0 -3
  124. data/lib/padrino/init.rb +0 -10
  125. data/lib/padrino/lib/helpers/collection.rb +0 -27
  126. data/lib/padrino/lib/padrino/view_models.rb +0 -19
  127. data/lib/padrino/lib/view_models/base.rb +0 -65
  128. data/lib/rails2/README.textile +0 -3
  129. data/lib/rails2/TODO.textile +0 -5
  130. data/lib/rails2/generators/view_models/USAGE +0 -6
  131. data/lib/rails2/generators/view_models/templates/README +0 -1
  132. data/lib/rails2/generators/view_models/templates/spec/view_model_spec.rb +0 -7
  133. data/lib/rails2/generators/view_models/templates/view_models/view_model.rb +0 -5
  134. data/lib/rails2/generators/view_models/templates/views/view_models/collection/_collection.html.erb +0 -1
  135. data/lib/rails2/generators/view_models/templates/views/view_models/collection/_collection.text.erb +0 -6
  136. data/lib/rails2/generators/view_models/templates/views/view_models/collection/_list.html.erb +0 -1
  137. data/lib/rails2/generators/view_models/templates/views/view_models/collection/_list.text.erb +0 -6
  138. data/lib/rails2/generators/view_models/templates/views/view_models/collection/_pagination.text.erb +0 -3
  139. data/lib/rails2/generators/view_models/templates/views/view_models/collection/_table.text.erb +0 -10
  140. data/lib/rails2/generators/view_models/view_models_generator.rb +0 -47
  141. data/lib/rails2/init.rb +0 -18
  142. data/lib/rails2/lib/experimental/README.textile +0 -32
  143. data/lib/rails2/lib/experimental/modules_in_render_hierarchy.rb +0 -21
  144. data/lib/rails2/lib/helpers/collection.rb +0 -27
  145. data/lib/rails2/lib/view_models.rb +0 -1
  146. data/lib/rails2/lib/view_models/base.rb +0 -99
  147. data/lib/shared/README.textile +0 -3
  148. data/lib/shared/init.rb +0 -11
  149. data/lib/shared/lib/view_models.rb +0 -4
  150. data/lib/shared/lib/view_models/extensions/active_record.rb +0 -27
  151. data/lib/shared/lib/view_models/helpers/collection.rb +0 -110
  152. data/spec/padrino/integration/integration_spec.rb +0 -287
  153. data/spec/padrino/lib/helpers/collection_spec.rb +0 -30
  154. data/spec/rails2/integration/integration_spec.rb +0 -279
  155. data/spec/rails2/lib/extensions/active_record_spec.rb +0 -31
  156. data/spec/rails2/lib/helpers/collection_spec.rb +0 -30
  157. data/spec/rails2/lib/view_models/view_spec.rb +0 -12
@@ -0,0 +1,113 @@
1
+ module ViewModels
2
+
3
+ # Helpers you can include in just about anything to get convenient access to view model functionality
4
+ #
5
+ module Helpers
6
+
7
+ # Mapping helpers install collection_view_model_for and view_model_for, which you can use with instances
8
+ # to conveniently instantiate a view model for it
9
+ #
10
+ module Mapping
11
+
12
+ # Construct a view_model for a collection.
13
+ #
14
+ # @todo Think about moving it into view_model_for, or renaming it view_models_for.
15
+ #
16
+ def collection_view_model_for array_or_pagination, context = self
17
+ Collection.new array_or_pagination, context
18
+ end
19
+
20
+ # The Collection view_model helper has the purpose of presenting presentable collections.
21
+ # * Render as list
22
+ # * Render as table
23
+ # * Render as collection
24
+ # * Render a pagination
25
+ #
26
+ class Collection
27
+
28
+ # Delegate collection relevant methods to the collection.
29
+ # @todo Why is as_json not yet loaded in Enumerable.instance_methods
30
+ # when this file is loaded in the spec, require active_support is installed before view_models are loaded
31
+ # Load Order ? Rails Blagic?
32
+ #
33
+ self.delegate *[Enumerable.instance_methods, :length, :size, :empty?, :each, :exit, :as_json, { :to => :@collection }].flatten
34
+
35
+ #
36
+ #
37
+ def initialize collection, context
38
+ @collection, @context = collection, context
39
+ end
40
+
41
+ # Renders a list (in the broadest sense of the word).
42
+ #
43
+ # @param [Hash] options The options for the list
44
+ # @option options :collection the collection to iterate over (default: The collection of the collection view_model to iterate over)
45
+ # @option options :context context to render in (default: The original context given to the collection view_model to render in)
46
+ # @option options :template_name the template to render for each model element (default: list_item as the default element template)
47
+ # @option options :separator the separator between each element (default: nil separator in html)
48
+ #
49
+ def list options = {}
50
+ render_partial :list, template_locals(:list_item, options)
51
+ end
52
+
53
+ # Renders a collection.
54
+ #
55
+ # @note The only difference between a list and a collection is the enclosing list type. While list uses ol, the collection uses ul.
56
+ #
57
+ # @param [Hash] options The options for the collection
58
+ # @option options :collection the collection to iterate over (default: The collection of the collection view_model to iterate over)
59
+ # @option options :context the context to render in (default: The original context given to the collection view_model to render in)
60
+ # @option options :template_name the template to render for each model element (default: Uses :collection_item as the default element template)
61
+ # @option options :separator => separator between each element (default: nil separator in html)
62
+ #
63
+ def collection options = {}
64
+ render_partial :collection, template_locals(:collection_item, options)
65
+ end
66
+
67
+ # Renders a table.
68
+ #
69
+ # Note: Each item represents a table row.
70
+ #
71
+ # @param [Hash] options The options for the table
72
+ # @option options :collection the collection to iterate over (default: The collection of the collection view_model to iterate over)
73
+ # @option options :context the context to render in (default: The original context given to the collection view_model to render in)
74
+ # @option options :template_name the template to render for each model element (default: Uses :table_row as the default element template)
75
+ # @option options :separator => separator between each element (default: nil separator in html)
76
+ #
77
+ def table options = {}
78
+ render_partial :table, template_locals(:table_row, options)
79
+ end
80
+
81
+ # Renders a pagination.
82
+ #
83
+ # @param [Hash] options The options for the collection
84
+ # @option options :collection the collection to iterate over (default: The collection of the collection view_model to iterate over)
85
+ # @option options :context the context to render in (default: The original context given to the collection view_model to render in)
86
+ # @option options :template_name the template to render for each model element (default: Uses :collection_item as the default element template)
87
+ # @option options :separator => separator between each element (default: | separator in html)
88
+ #
89
+ def pagination options = {}
90
+ render_partial :pagination, template_locals(:pagination, {:separator => '|'}.merge(options))
91
+ end
92
+
93
+ private
94
+
95
+ # Helper method that renders a partial in the context of the context instance.
96
+ #
97
+ # @note If the collection view_model helper has been instantiated in the context of a controller, render will be called in the controller.
98
+ #
99
+ def render_partial name, locals
100
+ @context.instance_eval { render :partial => "view_models/collection/#{name}", :locals => locals }
101
+ end
102
+
103
+ # Helper method that constructs locals for render_partial
104
+ #
105
+ def template_locals template_name, supersed_options
106
+ { :collection => @collection, :template_name => template_name, :separator => nil }.merge supersed_options
107
+ end
108
+
109
+ end
110
+
111
+ end
112
+ end
113
+ end
@@ -2,16 +2,20 @@ module ViewModels
2
2
  module Helpers
3
3
  module Mapping
4
4
 
5
+ # module attribute used for specific mapping
6
+ #
5
7
  mattr_accessor :specific_view_model_mapping
6
8
  self.specific_view_model_mapping = {}
7
9
 
10
+ # module attribute for the default view models prefix
11
+ #
12
+ mattr_accessor :default_prefix
13
+ self.default_prefix = 'ViewModels::'
14
+
8
15
  # Create a new view_model instance for the given model instance
9
16
  # with the given arguments.
10
- #
11
- # Note: Will emit an ArgumentError if the view model class doesn't support 2 arguments.
12
- #
13
- # Padrino: context is an app instance.
14
- # Rails 2: context is either a view instance or a controller instance.
17
+ # @raise [ArgumentError] if the view model class doesn't support 2 arguments.
18
+ # @note context is either a view instance or a controller instance.
15
19
  #
16
20
  def view_model_for model, context = self
17
21
  view_model_class_for(model).new model, context
@@ -19,12 +23,7 @@ module ViewModels
19
23
 
20
24
  # Get the view_model class for the given model instance.
21
25
  #
22
- # Note: ViewModels are usually of class ViewModels::<ModelClassName>.
23
- # (As returned by default_view_model_class_for)
24
- # Override specific_mapping if you'd like to install your own.
25
- #
26
- # OR: Override default_view_model_class_for(model) if
27
- # you'd like to change the default.
26
+ # @note ViewModels are usually of class ViewModels::<ModelClassName>. (As returned by default_view_model_class_for). Override specific_mapping if you'd like to install your own. Or Override default_view_model_class_for(model) if you'd like to change the default.
28
27
  #
29
28
  def view_model_class_for model
30
29
  specific_view_model_class_for(model) || default_view_model_class_for(model)
@@ -38,10 +37,8 @@ module ViewModels
38
37
  # Override this method if you'd like to change the _default_
39
38
  # model-to-view_model class mapping.
40
39
  #
41
- # Note: Will emit a NameError if a corresponding ViewModels constant cannot be loaded.
40
+ # @raise [NameError] if a corresponding ViewModels constant cannot be loaded.
42
41
  #
43
- mattr_accessor :default_prefix
44
- self.default_prefix = 'ViewModels::'
45
42
  def default_view_model_class_for model
46
43
  (default_prefix + model.class.name).constantize
47
44
  end
@@ -51,7 +48,7 @@ module ViewModels
51
48
  # Override this method, if you want to return a specific
52
49
  # view model class for the given model.
53
50
  #
54
- # Note: Will emit a NameError if a corresponding ViewModels constant cannot be loaded.
51
+ # @raise [NameError] if a corresponding ViewModels constant cannot be loaded.
55
52
  #
56
53
  def specific_view_model_class_for model
57
54
  specific_view_model_mapping[model.class]
@@ -1,15 +1,19 @@
1
1
  module ViewModels
2
2
  module Helpers
3
+
3
4
  # Module for conveniently including common view_helpers into a view_model
4
5
  #
5
6
  module View
6
7
 
7
- # Include hook.
8
+ # Include hook for the view
8
9
  #
9
10
  def self.included view_model
10
11
  view_model.send :include, *all_view_helpers
11
12
  end
12
13
 
14
+ # The common view helpers
15
+ # @return [Array] an array of common view helpers
16
+ #
13
17
  def self.all_view_helpers
14
18
  [
15
19
  ActionView::Helpers,
@@ -8,8 +8,13 @@ module ViewModels
8
8
  #
9
9
  class PathStore
10
10
 
11
+ # The view model class attribute
12
+ #
11
13
  attr_reader :view_model_class
12
14
 
15
+ # Initialize the path store
16
+ # @param [ViewModel] view_model_class The view model class
17
+ #
13
18
  def initialize view_model_class
14
19
  @view_model_class = view_model_class
15
20
  @name_path_mapping = {}
@@ -31,7 +36,7 @@ module ViewModels
31
36
 
32
37
  # Prepare the key for the next storing procedure.
33
38
  #
34
- # Note: If this is nil, the store will not save the path.
39
+ # @note If this is nil, the store will not save the path.
35
40
  #
36
41
  def prepare key
37
42
  @key = key
@@ -1,8 +1,6 @@
1
1
  module ViewModels
2
2
 
3
3
  # Container object for render options.
4
- #
5
- # TODO Make a rails exclusive.
6
4
  #
7
5
  module RenderOptions
8
6
 
@@ -10,8 +8,15 @@ module ViewModels
10
8
  #
11
9
  class Base
12
10
 
11
+ # The different attributes used to generate render options
12
+ #
13
13
  attr_accessor :path, :name, :prefix, :file, :view_model, :format
14
14
 
15
+ # Initialize Render Options
16
+ # @param [String] prefix The prefix for rendering
17
+ # @param [String] name The template name
18
+ # @param [Hash] options The render options as a hash
19
+ #
15
20
  def initialize prefix, name, options
16
21
  @prefix = prefix
17
22
  @options = options
@@ -24,16 +29,25 @@ module ViewModels
24
29
  def error_message
25
30
  "'#{error_path}#{name}' with #{error_format}"
26
31
  end
32
+
33
+ # The error path, always returns a string
34
+ # @return [String] The error path
35
+ #
27
36
  def error_path
28
37
  path = self.path
29
38
  path ? "#{path}/" : ""
30
39
  end
40
+
41
+ # The format when trying to render
42
+ # @return [String] the render format
43
+ #
31
44
  def error_format
32
45
  format = self.format
33
46
  format ? "format #{format}" : "default format"
34
47
  end
35
48
 
36
49
  # Used when rendering.
50
+ # @return [Hash] The render options
37
51
  #
38
52
  def to_render_options
39
53
  @options[:locals] ||= {}
@@ -41,7 +55,8 @@ module ViewModels
41
55
  @options.reverse_merge :file => file
42
56
  end
43
57
 
44
- # TODO Rails specific.
58
+ # @todo Rails specific.
59
+ # @param [ActionView] view The view to render
45
60
  #
46
61
  def format! view
47
62
  view.template_format = @format if @format
@@ -55,7 +70,7 @@ module ViewModels
55
70
 
56
71
  private
57
72
 
58
- # TODO rewrite
73
+ # @todo rewrite
59
74
  #
60
75
  def template_name= template_name
61
76
  template_name.to_s.include?('/') ? specific_path(template_name) : incomplete_path(template_name)
@@ -0,0 +1,5 @@
1
+ module ViewModels
2
+ # The current version of the gem
3
+ #
4
+ VERSION = '3.0.0'.freeze
5
+ end
@@ -5,7 +5,8 @@ module ViewModels
5
5
 
6
6
  # Shut up, opinionated funkers.
7
7
  #
8
- alias singleton_class metaclass unless instance_methods.include?('singleton_class')
8
+ alias singleton_class metaclass unless instance_methods.include?(:singleton_class) || instance_methods.include?('singleton_class')
9
+
9
10
 
10
11
  # Include the helpers from the view model.
11
12
  #
@@ -19,12 +20,12 @@ module ViewModels
19
20
  def render_with options
20
21
  render options.to_render_options
21
22
  end
22
-
23
- # Finds the template in the view paths at the given path, with its format.
23
+
24
+ # Rails 3 calls it with 2 arguments
24
25
  #
25
- def find_template path
26
- view_paths.find_template path, template_format rescue nil
26
+ def find_template path, second=nil
27
+ lookup_context.find_template path rescue nil
27
28
  end
28
-
29
+
29
30
  end
30
31
  end
@@ -1,4 +1,4 @@
1
- require File.join(File.dirname(__FILE__), '/../../spec_helper')
1
+ require 'spec_helper'
2
2
 
3
3
  describe ViewModels::Base do
4
4
 
@@ -53,16 +53,49 @@ describe ViewModels::Base do
53
53
  end
54
54
  end
55
55
 
56
+ describe "to_param" do
57
+ before(:each) do
58
+ @model = stub :model
59
+ @view_model = ViewModels::Base.new @model, nil
60
+ end
61
+ it "should delegate to_param to the model" do
62
+ @model.should_receive(:to_param).once
63
+
64
+ @view_model.to_param
65
+ end
66
+
67
+ it "should delegate id to the model" do
68
+ @model.should_receive(:id).once
69
+
70
+ @view_model.id
71
+ end
72
+
73
+ it "should delegate dom_id with no args to ActionController::RecordIdentifier" do
74
+ ActionController::RecordIdentifier.should_receive(:dom_id).once
75
+
76
+ @view_model.dom_id
77
+ end
78
+
79
+ it "should delegate dom_id with args to the context" do
80
+ @context = mock('context')
81
+ @view_model.stub! :context => @context
82
+ @context.should_receive(:dom_id).with('arg1', 'arg2').once
83
+
84
+ @view_model.dom_id('arg1', 'arg2')
85
+ end
86
+
87
+ end
88
+
56
89
  describe ".master_helper_module" do
57
90
  before(:each) do
58
91
  class ViewModels::SpecificMasterHelperModule < ViewModels::Base; end
59
92
  end
60
93
  it "should be a class specific inheritable accessor" do
61
- ViewModels::SpecificMasterHelperModule.master_helper_module = :some_value
62
- ViewModels::SpecificMasterHelperModule.master_helper_module.should == :some_value
94
+ ViewModels::SpecificMasterHelperModule._helpers = :some_value
95
+ ViewModels::SpecificMasterHelperModule._helpers.should == :some_value
63
96
  end
64
97
  it "should be an instance of Module on Base" do
65
- ViewModels::Base.master_helper_module.should be_instance_of(Module)
98
+ ViewModels::Base._helpers.should be_instance_of(Module)
66
99
  end
67
100
  end
68
101
 
@@ -84,7 +117,7 @@ describe ViewModels::Base do
84
117
  end
85
118
  it "should include the helper in the master helper module" do
86
119
  master_helper_module = Module.new
87
- ViewModels::Base.should_receive(:master_helper_module).and_return master_helper_module
120
+ ViewModels::Base.should_receive(:_helpers).and_return master_helper_module
88
121
 
89
122
  helper_module = Module.new
90
123
  master_helper_module.should_receive(:include).once.with helper_module
@@ -1,4 +1,4 @@
1
- require File.join(File.dirname(__FILE__), '/../../spec_helper')
1
+ require 'spec_helper'
2
2
 
3
3
  describe ViewModels::Extensions::ModelReader do
4
4
 
@@ -25,7 +25,7 @@ describe ViewModels::Extensions::ModelReader do
25
25
  @view_model.some_model_value.should == 's'
26
26
  end
27
27
  it "should call filters in a given pattern" do
28
- @view_model.class.model_reader [:some_model_value], :filter_through => [:a, :b, :a, :a]
28
+ @view_model.class.model_reader :some_model_value, :filter_through => [:a, :b, :a, :a]
29
29
 
30
30
  @view_model.some_model_value.should == 'sabaa'
31
31
  end
@@ -34,8 +34,8 @@ describe ViewModels::Extensions::ModelReader do
34
34
 
35
35
  lambda { @view_model.some_model_value }.should_not raise_error
36
36
  end
37
- it "should handle an array of readers" do
38
- @view_model.class.model_reader [:some_model_value, :some_other_model_value], :filter_through => :a
37
+ it "should handle multiple readers" do
38
+ @view_model.class.model_reader :some_model_value, :some_other_model_value, :filter_through => :a
39
39
 
40
40
  lambda { @view_model.some_model_value }.should_not raise_error
41
41
  end
@@ -1,4 +1,4 @@
1
- require File.join(File.dirname(__FILE__), '../../spec_helper')
1
+ require 'spec_helper'
2
2
 
3
3
  describe ViewModels::Helpers::Mapping::Collection do
4
4
  include ViewModels::Helpers::Mapping
@@ -9,6 +9,24 @@ describe ViewModels::Helpers::Mapping::Collection do
9
9
  @collection_view_model = ViewModels::Helpers::Mapping::Collection.new @collection, @context
10
10
  end
11
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
+
12
30
  describe "collection_view_model_for" do
13
31
  it "should return kind of a ViewModels::Collection" do
14
32
  collection_view_model_for([]).should be_kind_of ViewModels::Helpers::Mapping::Collection
@@ -119,6 +137,7 @@ describe ViewModels::Helpers::Mapping::Collection do
119
137
  it "should call render_partial with the right parameters" do
120
138
  default_options = {
121
139
  :collection => @collection,
140
+ :template_name => :pagination,
122
141
  :separator => '|'
123
142
  }
124
143
  @collection_view_model.should_receive(:render_partial).once.with :pagination, default_options
@@ -128,6 +147,7 @@ describe ViewModels::Helpers::Mapping::Collection do
128
147
  it "should override the default options if specific options are given" do
129
148
  specific_options = {
130
149
  :collection => :a,
150
+ :template_name => :b,
131
151
  :separator => :c
132
152
  }
133
153
  @collection_view_model.should_receive(:render_partial).once.with :pagination, specific_options