view_mapper 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (108) hide show
  1. data/README.rdoc +4 -2
  2. data/VERSION +1 -1
  3. data/generators/scaffold_for_view/scaffold_for_view_generator.rb +2 -6
  4. data/generators/view_for/view_for_generator.rb +1 -5
  5. data/lib/view_mapper/{has_many_view.rb → has_many_child_models.rb} +33 -37
  6. data/lib/view_mapper/model_info.rb +8 -0
  7. data/lib/view_mapper/view_mapper.rb +15 -2
  8. data/lib/view_mapper/views/auto_complete/auto_complete_view.rb +77 -0
  9. data/lib/view_mapper/{auto_complete_templates → views/auto_complete/templates}/controller.rb +3 -1
  10. data/lib/view_mapper/{auto_complete_templates → views/auto_complete/templates}/layout.html.erb +0 -0
  11. data/lib/view_mapper/{auto_complete_templates → views/auto_complete/templates}/view_edit.html.erb +1 -1
  12. data/lib/view_mapper/{auto_complete_templates → views/auto_complete/templates}/view_new.html.erb +1 -1
  13. data/lib/view_mapper/views/has_many/has_many_view.rb +28 -0
  14. data/lib/view_mapper/{has_many_templates → views/has_many/templates}/helper.rb +0 -0
  15. data/lib/view_mapper/{has_many_templates → views/has_many/templates}/layout.html.erb +0 -0
  16. data/lib/view_mapper/{has_many_templates → views/has_many/templates}/model.rb +0 -0
  17. data/lib/view_mapper/{has_many_templates → views/has_many/templates}/nested_attributes.js +0 -0
  18. data/lib/view_mapper/{has_many_templates → views/has_many/templates}/style.css +0 -0
  19. data/lib/view_mapper/{has_many_templates → views/has_many/templates}/view_child_form.html.erb +0 -0
  20. data/lib/view_mapper/{has_many_templates → views/has_many/templates}/view_edit.html.erb +0 -0
  21. data/lib/view_mapper/{has_many_templates → views/has_many/templates}/view_form.html.erb +0 -0
  22. data/lib/view_mapper/{has_many_templates → views/has_many/templates}/view_new.html.erb +0 -0
  23. data/lib/view_mapper/{has_many_templates → views/has_many/templates}/view_show.html.erb +0 -0
  24. data/lib/view_mapper/{paperclip_view.rb → views/paperclip/paperclip_view.rb} +6 -2
  25. data/lib/view_mapper/{paperclip_templates → views/paperclip/templates}/migration.rb +1 -1
  26. data/lib/view_mapper/{paperclip_templates → views/paperclip/templates}/model.rb +0 -0
  27. data/lib/view_mapper/{paperclip_templates → views/paperclip/templates}/view_edit.html.erb +0 -0
  28. data/lib/view_mapper/{paperclip_templates → views/paperclip/templates}/view_new.html.erb +0 -0
  29. data/lib/view_mapper/{paperclip_templates → views/paperclip/templates}/view_show.html.erb +0 -0
  30. data/lib/view_mapper.rb +4 -3
  31. data/test/{fake → generators/fake}/fake_generator.rb +0 -0
  32. data/test/generators/fake/templates/fake_template1.html.erb +1 -0
  33. data/test/generators/fake/templates/fake_template2.html.erb +1 -0
  34. data/test/{scaffold_for_view_generator_test.rb → generators/scaffold_for_view/scaffold_for_view_generator_test.rb} +2 -2
  35. data/test/{view_for_generator_test.rb → generators/view_for/view_for_generator_test.rb} +0 -0
  36. data/test/model_info_test.rb +12 -3
  37. data/test/test_helper.rb +12 -8
  38. data/test/view_mapper_test.rb +13 -2
  39. data/test/{auto_complete_test.rb → views/auto_complete/auto_complete_test.rb} +63 -40
  40. data/test/{expected_templates/auto_complete/index.html.erb → views/auto_complete/expected_templates/actual_index} +2 -0
  41. data/test/{expected_templates/auto_complete → views/auto_complete/expected_templates}/edit.html.erb +7 -3
  42. data/test/{expected_templates/auto_complete → views/auto_complete/expected_templates}/expected_routes.rb +0 -0
  43. data/test/{expected_templates/paperclip → views/auto_complete/expected_templates}/index.html.erb +3 -1
  44. data/test/{expected_templates/auto_complete → views/auto_complete/expected_templates}/new.html.erb +7 -3
  45. data/test/{expected_templates/auto_complete → views/auto_complete/expected_templates}/show.html.erb +6 -1
  46. data/test/{expected_templates/auto_complete → views/auto_complete/expected_templates}/standard_routes.rb +0 -0
  47. data/test/{expected_templates/auto_complete → views/auto_complete/expected_templates}/testies.html.erb +0 -0
  48. data/test/{expected_templates/auto_complete → views/auto_complete/expected_templates}/testies_controller.rb +2 -1
  49. data/test/views/fake/fake_view.rb +7 -0
  50. data/test/views/fake/templates/fake_template1.html.erb +1 -0
  51. data/test/{expected_templates/has_many → views/has_many/expected_templates}/_form.html.erb +0 -0
  52. data/test/{expected_templates/has_many → views/has_many/expected_templates}/_person.html.erb +4 -0
  53. data/test/{expected_templates/has_many → views/has_many/expected_templates}/create_parents.rb +4 -3
  54. data/test/{expected_templates/has_many → views/has_many/expected_templates}/edit.html.erb +0 -0
  55. data/test/{expected_templates/has_many → views/has_many/expected_templates}/index.html.erb +1 -1
  56. data/test/{expected_templates/has_many → views/has_many/expected_templates}/new.html.erb +0 -0
  57. data/test/{expected_templates/has_many → views/has_many/expected_templates}/parent.rb +2 -1
  58. data/test/{expected_templates/has_many → views/has_many/expected_templates}/show.html.erb +4 -0
  59. data/test/{has_many_view_test.rb → views/has_many/has_many_view_test.rb} +17 -17
  60. data/test/{expected_templates/paperclip → views/paperclip/expected_templates}/create_testies.rb +4 -3
  61. data/test/{expected_templates/paperclip → views/paperclip/expected_templates}/edit.html.erb +4 -0
  62. data/test/views/paperclip/expected_templates/index.html.erb +26 -0
  63. data/test/{expected_templates/paperclip → views/paperclip/expected_templates}/new.html.erb +4 -0
  64. data/test/{expected_templates/paperclip → views/paperclip/expected_templates}/show.html.erb +5 -0
  65. data/test/{expected_templates/paperclip → views/paperclip/expected_templates}/testy.rb +0 -0
  66. data/test/{paperclip_view_test.rb → views/paperclip/paperclip_view_test.rb} +17 -9
  67. data/view_mapper.gemspec +77 -124
  68. metadata +72 -120
  69. data/lib/view_mapper/auto_complete_templates/functional_test.rb +0 -45
  70. data/lib/view_mapper/auto_complete_templates/helper.rb +0 -2
  71. data/lib/view_mapper/auto_complete_templates/helper_test.rb +0 -4
  72. data/lib/view_mapper/auto_complete_templates/style.css +0 -54
  73. data/lib/view_mapper/auto_complete_templates/view_index.html.erb +0 -24
  74. data/lib/view_mapper/auto_complete_templates/view_show.html.erb +0 -10
  75. data/lib/view_mapper/auto_complete_view.rb +0 -44
  76. data/lib/view_mapper/has_many_templates/controller.rb +0 -85
  77. data/lib/view_mapper/has_many_templates/fixtures.yml +0 -19
  78. data/lib/view_mapper/has_many_templates/functional_test.rb +0 -45
  79. data/lib/view_mapper/has_many_templates/helper_test.rb +0 -4
  80. data/lib/view_mapper/has_many_templates/migration.rb +0 -16
  81. data/lib/view_mapper/has_many_templates/unit_test.rb +0 -8
  82. data/lib/view_mapper/has_many_templates/view_index.html.erb +0 -24
  83. data/lib/view_mapper/paperclip_templates/controller.rb +0 -85
  84. data/lib/view_mapper/paperclip_templates/fixtures.yml +0 -19
  85. data/lib/view_mapper/paperclip_templates/functional_test.rb +0 -45
  86. data/lib/view_mapper/paperclip_templates/helper.rb +0 -2
  87. data/lib/view_mapper/paperclip_templates/helper_test.rb +0 -4
  88. data/lib/view_mapper/paperclip_templates/layout.html.erb +0 -17
  89. data/lib/view_mapper/paperclip_templates/style.css +0 -54
  90. data/lib/view_mapper/paperclip_templates/unit_test.rb +0 -8
  91. data/lib/view_mapper/paperclip_templates/view_index.html.erb +0 -24
  92. data/test/database.yml +0 -3
  93. data/test/fake_view.rb +0 -7
  94. data/test/rails_generator/base.rb +0 -266
  95. data/test/rails_generator/commands.rb +0 -621
  96. data/test/rails_generator/generated_attribute.rb +0 -46
  97. data/test/rails_generator/generators/components/model/model_generator.rb +0 -45
  98. data/test/rails_generator/generators/components/scaffold/scaffold_generator.rb +0 -102
  99. data/test/rails_generator/lookup.rb +0 -249
  100. data/test/rails_generator/manifest.rb +0 -53
  101. data/test/rails_generator/options.rb +0 -150
  102. data/test/rails_generator/scripts/destroy.rb +0 -29
  103. data/test/rails_generator/scripts/generate.rb +0 -7
  104. data/test/rails_generator/scripts/update.rb +0 -12
  105. data/test/rails_generator/scripts.rb +0 -89
  106. data/test/rails_generator/secret_key_generator.rb +0 -24
  107. data/test/rails_generator/simple_logger.rb +0 -46
  108. data/test/rails_generator/spec.rb +0 -44
@@ -1,53 +1,69 @@
1
- require 'test_helper'
1
+ require File.dirname(__FILE__) + '/../../test_helper'
2
2
 
3
3
  class AutoCompleteViewTest < Test::Unit::TestCase
4
4
 
5
5
  attr_reader :singular_name
6
6
  attr_reader :plural_name
7
7
  attr_reader :attributes
8
- attr_reader :auto_complete_attribute
8
+ attr_reader :auto_complete_attributes
9
9
  attr_reader :controller_class_name
10
10
  attr_reader :table_name
11
11
  attr_reader :class_name
12
12
  attr_reader :file_name
13
13
  attr_reader :controller_singular_name
14
14
 
15
+ context "A view_for generator instantiated for a test model" do
16
+ setup do
17
+ setup_test_model
18
+ end
19
+
20
+ should "detect all of the text fields when no auto_complete field is specified" do
21
+ gen = new_generator_for_test_model('view_for', ['--view', 'auto_complete'])
22
+ assert_contains gen.auto_complete_attributes, 'first_name'
23
+ assert_contains gen.auto_complete_attributes, 'last_name'
24
+ assert_contains gen.auto_complete_attributes, 'address'
25
+ assert_does_not_contain gen.auto_complete_attributes, 'some_flag'
26
+ end
27
+ end
28
+
29
+ context "A scaffold_for_view generator instantiated for a test model" do
30
+ setup do
31
+ setup_test_model
32
+ end
33
+
34
+ should "return an error message without an auto_complete param" do
35
+ Rails::Generator::Base.logger.expects('error').with('No auto_complete attribute specified.')
36
+ new_generator_for_test_model('scaffold_for_view', ['--view', 'auto_complete'])
37
+ end
38
+ end
39
+
15
40
  generators = %w{ view_for scaffold_for_view }
16
41
  generators.each do |gen|
17
42
 
18
43
  context "A #{gen} generator instantiated for a test model" do
19
- should "return an error message without an auto_complete param" do
20
- Rails::Generator::Base.logger.expects('error').with('No auto_complete attribute specified.')
21
- new_generator_for_test_model(gen, ['--view', 'auto_complete'])
44
+ setup do
45
+ setup_test_model
22
46
  end
23
47
 
24
48
  should "return an error message with a bad auto_complete param" do
25
49
  Rails::Generator::Base.logger.expects('error').with('Field \'blah\' does not exist.')
26
50
  new_generator_for_test_model(gen, ['--view', 'auto_complete:blah'])
27
51
  end
28
- end
29
52
 
30
- context "A #{gen} generator instantiated for a test model with auto_complete on the first_name field" do
31
- setup do
32
- @gen = new_generator_for_test_model(gen, ['--view', 'auto_complete:first_name'])
33
- end
34
-
35
- should "find the auto complete column name" do
36
- assert_equal 'first_name', @gen.auto_complete_attribute
37
- end
38
-
39
- should "have the correct auto_complete_for method name" do
40
- assert_equal 'auto_complete_for_testy_first_name', @gen.auto_complete_for_method
53
+ should "return an error message when the auto_complete param matches a field that is not a text field" do
54
+ Rails::Generator::Base.logger.expects('error').with('Field \'some_flag\' is not a text field.')
55
+ new_generator_for_test_model(gen, ['--view', 'auto_complete:some_flag'])
41
56
  end
42
57
  end
43
58
 
44
- context "A #{gen} generator instantiated for a test model with auto_complete on the address field" do
59
+ context "A #{gen} generator instantiated for a test model with auto_complete on the first and last name fields" do
45
60
  setup do
46
- @gen = new_generator_for_test_model(gen, ['--view', 'auto_complete:address'])
61
+ setup_test_model
62
+ @gen = new_generator_for_test_model(gen, ['--view', 'auto_complete:first_name,last_name'])
47
63
  end
48
64
 
49
- should "return the proper source root folder" do
50
- assert_equal './test/../lib/view_mapper/auto_complete_templates', @gen.source_root
65
+ should "return the proper source root" do
66
+ assert_equal File.expand_path(File.dirname(__FILE__) + '/../../..//lib/view_mapper/views/auto_complete/templates'), ViewMapper::AutoCompleteView.source_root
51
67
  end
52
68
 
53
69
  view_for_templates = %w{ new edit index show }
@@ -56,19 +72,19 @@ class AutoCompleteViewTest < Test::Unit::TestCase
56
72
  @attributes = @gen.attributes
57
73
  @singular_name = @gen.singular_name
58
74
  @plural_name = @gen.plural_name
59
- @auto_complete_attribute = @gen.auto_complete_attribute
60
- template_file = File.open(File.join(File.dirname(__FILE__), "/../lib/view_mapper/auto_complete_templates/view_#{template}.html.erb"))
75
+ @auto_complete_attributes = @gen.auto_complete_attributes
76
+ template_file = File.open(@gen.source_path("view_#{template}.html.erb"))
61
77
  result = ERB.new(template_file.read, nil, '-').result(binding)
62
- expected_file = File.open(File.join(File.dirname(__FILE__), "expected_templates/auto_complete/#{template}.html.erb"))
78
+ expected_file = File.open(File.join(File.dirname(__FILE__), "expected_templates/#{template}.html.erb"), 'rb')
63
79
  assert_equal expected_file.read, result
64
80
  end
65
81
  end
66
82
 
67
83
  should "render the layout template as expected" do
68
84
  @controller_class_name = @gen.controller_class_name
69
- template_file = File.open(File.join(File.dirname(__FILE__), "/../lib/view_mapper/auto_complete_templates/layout.html.erb"))
85
+ template_file = File.open(@gen.source_path("layout.html.erb"))
70
86
  result = ERB.new(template_file.read, nil, '-').result(binding)
71
- expected_file = File.open(File.join(File.dirname(__FILE__), "expected_templates/auto_complete/testies.html.erb"))
87
+ expected_file = File.open(File.join(File.dirname(__FILE__), "expected_templates/testies.html.erb"))
72
88
  assert_equal expected_file.read, result
73
89
  end
74
90
 
@@ -78,10 +94,10 @@ class AutoCompleteViewTest < Test::Unit::TestCase
78
94
  @class_name = @gen.class_name
79
95
  @file_name = @gen.file_name
80
96
  @controller_singular_name = @gen.controller_singular_name
81
- @auto_complete_attribute = @gen.auto_complete_attribute
82
- template_file = File.open(File.join(File.dirname(__FILE__), "/../lib/view_mapper/auto_complete_templates/controller.rb"))
97
+ @auto_complete_attributes = @gen.auto_complete_attributes
98
+ template_file = File.open(@gen.source_path("controller.rb"))
83
99
  result = ERB.new(template_file.read, nil, '-').result(binding)
84
- expected_file = File.open(File.join(File.dirname(__FILE__), "expected_templates/auto_complete/testies_controller.rb"))
100
+ expected_file = File.open(File.join(File.dirname(__FILE__), "expected_templates/testies_controller.rb"))
85
101
  assert_equal expected_file.read, result
86
102
  end
87
103
  end
@@ -100,7 +116,7 @@ class AutoCompleteViewTest < Test::Unit::TestCase
100
116
  Rails::Generator::Commands::Create.any_instance.stubs(:dependency)
101
117
  Rails::Generator::Base.logger.stubs(:route)
102
118
 
103
- expected_path = File.dirname(__FILE__) + '/expected_templates/auto_complete'
119
+ expected_path = File.dirname(__FILE__) + '/expected_templates'
104
120
  standard_routes_file = expected_path + '/standard_routes.rb'
105
121
  expected_routes_file = expected_path + '/expected_routes.rb'
106
122
  test_routes_file = expected_path + '/routes.rb'
@@ -112,17 +128,24 @@ class AutoCompleteViewTest < Test::Unit::TestCase
112
128
  assert_equal File.open(expected_routes_file).read, File.open(test_routes_file).read
113
129
  File.delete(test_routes_file)
114
130
  end
131
+ end
132
+ end
115
133
 
116
- should "not perform any actions when run on the #{gen} generator with no auto_complete field" do
117
- Rails::Generator::Commands::Create.any_instance.expects(:directory).never
118
- Rails::Generator::Commands::Create.any_instance.expects(:template).never
119
- Rails::Generator::Commands::Create.any_instance.expects(:route_resources).never
120
- Rails::Generator::Commands::Create.any_instance.expects(:file).never
121
- Rails::Generator::Commands::Create.any_instance.expects(:route).never
122
- Rails::Generator::Base.logger.stubs(:error)
123
- Rails::Generator::Base.logger.stubs(:route)
124
- @generator_script.run(generator_script_cmd_line(gen, ['--view', 'auto_complete']))
125
- end
134
+ context "A Rails generator script" do
135
+ setup do
136
+ setup_test_model
137
+ @generator_script = Rails::Generator::Scripts::Generate.new
138
+ end
139
+
140
+ should "not perform any actions when run on the scaffold_for_view generator with no auto_complete field" do
141
+ Rails::Generator::Commands::Create.any_instance.expects(:directory).never
142
+ Rails::Generator::Commands::Create.any_instance.expects(:template).never
143
+ Rails::Generator::Commands::Create.any_instance.expects(:route_resources).never
144
+ Rails::Generator::Commands::Create.any_instance.expects(:file).never
145
+ Rails::Generator::Commands::Create.any_instance.expects(:route).never
146
+ Rails::Generator::Base.logger.stubs(:error)
147
+ Rails::Generator::Base.logger.stubs(:route)
148
+ @generator_script.run(generator_script_cmd_line('scaffold_for_view', ['--view', 'auto_complete']))
126
149
  end
127
150
  end
128
151
 
@@ -5,6 +5,7 @@
5
5
  <th>First name</th>
6
6
  <th>Last name</th>
7
7
  <th>Address</th>
8
+ <th>Some flag</th>
8
9
  </tr>
9
10
 
10
11
  <% @testies.each do |testy| %>
@@ -12,6 +13,7 @@
12
13
  <td><%=h testy.first_name %></td>
13
14
  <td><%=h testy.last_name %></td>
14
15
  <td><%=h testy.address %></td>
16
+ <td><%=h testy.some_flag %></td>
15
17
  <td><%= link_to 'Show', testy %></td>
16
18
  <td><%= link_to 'Edit', edit_testy_path(testy) %></td>
17
19
  <td><%= link_to 'Destroy', testy, :confirm => 'Are you sure?', :method => :delete %></td>
@@ -4,15 +4,19 @@
4
4
  <%= f.error_messages %>
5
5
  <p>
6
6
  <%= f.label :first_name %><br />
7
- <%= f.text_field :first_name %>
7
+ <%= text_field_with_auto_complete :testy, :first_name, {}, { :method => :get } %>
8
8
  </p>
9
9
  <p>
10
10
  <%= f.label :last_name %><br />
11
- <%= f.text_field :last_name %>
11
+ <%= text_field_with_auto_complete :testy, :last_name, {}, { :method => :get } %>
12
12
  </p>
13
13
  <p>
14
14
  <%= f.label :address %><br />
15
- <%= text_field_with_auto_complete :testy, :address, {}, { :method => :get } %>
15
+ <%= f.text_field :address %>
16
+ </p>
17
+ <p>
18
+ <%= f.label :some_flag %><br />
19
+ <%= f.check_box :some_flag %>
16
20
  </p>
17
21
  <p>
18
22
  <%= f.submit 'Update' %>
@@ -5,6 +5,7 @@
5
5
  <th>First name</th>
6
6
  <th>Last name</th>
7
7
  <th>Address</th>
8
+ <th>Some flag</th>
8
9
  </tr>
9
10
 
10
11
  <% @testies.each do |testy| %>
@@ -12,6 +13,7 @@
12
13
  <td><%=h testy.first_name %></td>
13
14
  <td><%=h testy.last_name %></td>
14
15
  <td><%=h testy.address %></td>
16
+ <td><%=h testy.some_flag %></td>
15
17
  <td><%= link_to 'Show', testy %></td>
16
18
  <td><%= link_to 'Edit', edit_testy_path(testy) %></td>
17
19
  <td><%= link_to 'Destroy', testy, :confirm => 'Are you sure?', :method => :delete %></td>
@@ -21,4 +23,4 @@
21
23
 
22
24
  <br />
23
25
 
24
- <%= link_to 'New testy', new_testy_path %>
26
+ <%= link_to 'New testy', new_testy_path %>
@@ -4,15 +4,19 @@
4
4
  <%= f.error_messages %>
5
5
  <p>
6
6
  <%= f.label :first_name %><br />
7
- <%= f.text_field :first_name %>
7
+ <%= text_field_with_auto_complete :testy, :first_name, {}, { :method => :get } %>
8
8
  </p>
9
9
  <p>
10
10
  <%= f.label :last_name %><br />
11
- <%= f.text_field :last_name %>
11
+ <%= text_field_with_auto_complete :testy, :last_name, {}, { :method => :get } %>
12
12
  </p>
13
13
  <p>
14
14
  <%= f.label :address %><br />
15
- <%= text_field_with_auto_complete :testy, :address, {}, { :method => :get } %>
15
+ <%= f.text_field :address %>
16
+ </p>
17
+ <p>
18
+ <%= f.label :some_flag %><br />
19
+ <%= f.check_box :some_flag %>
16
20
  </p>
17
21
  <p>
18
22
  <%= f.submit 'Create' %>
@@ -13,6 +13,11 @@
13
13
  <%=h @testy.address %>
14
14
  </p>
15
15
 
16
+ <p>
17
+ <b>Some flag:</b>
18
+ <%=h @testy.some_flag %>
19
+ </p>
20
+
16
21
 
17
22
  <%= link_to 'Edit', edit_testy_path(@testy) %> |
18
- <%= link_to 'Back', testies_path %>
23
+ <%= link_to 'Back', testies_path %>
@@ -1,6 +1,7 @@
1
1
  class TestiesController < ApplicationController
2
2
 
3
- auto_complete_for :testy, :address
3
+ auto_complete_for :testy, :first_name
4
+ auto_complete_for :testy, :last_name
4
5
 
5
6
  # GET /testies
6
7
  # GET /testies.xml
@@ -0,0 +1,7 @@
1
+ module ViewMapper
2
+ module FakeView
3
+ def self.source_root
4
+ File.expand_path(File.dirname(__FILE__) + '/templates')
5
+ end
6
+ end
7
+ end
@@ -0,0 +1 @@
1
+ This is fake.
@@ -11,6 +11,10 @@
11
11
  Testy <%= f.label :address %><br />
12
12
  <%= f.text_field :address %>
13
13
  </p>
14
+ <p>
15
+ Testy <%= f.label :some_flag %><br />
16
+ <%= f.check_box :some_flag %>
17
+ </p>
14
18
  <p>
15
19
  <%= f.hidden_field :_delete, :class => 'delete' %>
16
20
  <%= remove_child_link 'remove', f %>
@@ -1,9 +1,10 @@
1
1
  class CreateParents < ActiveRecord::Migration
2
2
  def self.up
3
3
  create_table :parents do |t|
4
- t.string :first_name
5
- t.string :last_name
6
- t.string :address
4
+ t.string :first_name
5
+ t.string :last_name
6
+ t.string :address
7
+ t.boolean :some_flag
7
8
 
8
9
  t.timestamps
9
10
  end
@@ -17,4 +17,4 @@
17
17
 
18
18
  <br />
19
19
 
20
- <%= link_to 'New parent', new_parent_path %>
20
+ <%= link_to 'New parent', new_parent_path %>
@@ -9,6 +9,7 @@ class Parent < ActiveRecord::Base
9
9
  :reject_if => proc { |attrs|
10
10
  attrs['first_name'].blank? &&
11
11
  attrs['last_name'].blank? &&
12
- attrs['address'].blank?
12
+ attrs['address'].blank? &&
13
+ attrs['some_flag'].blank?
13
14
  }
14
15
  end
@@ -26,6 +26,10 @@
26
26
  <b>Testy Address:</b>
27
27
  <%=h testy.address %>
28
28
  </p>
29
+ <p>
30
+ <b>Testy Some flag:</b>
31
+ <%=h testy.some_flag %>
32
+ </p>
29
33
  </div>
30
34
  <% end %>
31
35
 
@@ -1,4 +1,4 @@
1
- require 'test_helper'
1
+ require File.dirname(__FILE__) + '/../../test_helper'
2
2
 
3
3
  class HasManyViewTest < Test::Unit::TestCase
4
4
 
@@ -26,8 +26,8 @@ class HasManyViewTest < Test::Unit::TestCase
26
26
  assert_equal 2, child_models.size
27
27
  assert_equal 'SomeOtherModel', child_models[0].name
28
28
  assert_equal 'Testy', child_models[1].name
29
- assert_equal [ 'name' ], child_models[0].columns
30
- assert_equal [ 'first_name', 'last_name', 'address' ], child_models[1].columns
29
+ assert_equal [ 'name' ], child_models[0].columns
30
+ assert_equal [ 'first_name', 'last_name', 'address', 'some_flag' ], child_models[1].columns
31
31
  end
32
32
 
33
33
  should "use find the specified valid child model if provided" do
@@ -43,8 +43,8 @@ class HasManyViewTest < Test::Unit::TestCase
43
43
  assert_equal 2, gen.child_models.size
44
44
  assert_equal 'Testy', child_models[0].name
45
45
  assert_equal 'SomeOtherModel', child_models[1].name
46
- assert_equal [ 'first_name', 'last_name', 'address' ], child_models[0].columns
47
- assert_equal [ 'name' ], child_models[1].columns
46
+ assert_equal [ 'name' ], child_models[1].columns
47
+ assert_equal [ 'first_name', 'last_name', 'address', 'some_flag' ], child_models[0].columns
48
48
  end
49
49
 
50
50
  should "return an error message with a bad child model param" do
@@ -117,8 +117,8 @@ class HasManyViewTest < Test::Unit::TestCase
117
117
  @gen = new_generator_for_test_model('view_for', ['--view', 'has_many'], 'parent')
118
118
  end
119
119
 
120
- should "return the proper source root folder" do
121
- assert_equal './test/../lib/view_mapper/has_many_templates', @gen.source_root
120
+ should "return the proper source root" do
121
+ assert_equal File.expand_path(File.dirname(__FILE__) + '/../../..//lib/view_mapper/views/has_many/templates'), ViewMapper::HasManyView.source_root
122
122
  end
123
123
 
124
124
  view_for_templates = %w{ new edit show index }
@@ -128,9 +128,9 @@ class HasManyViewTest < Test::Unit::TestCase
128
128
  @singular_name = @gen.singular_name
129
129
  @plural_name = @gen.plural_name
130
130
  @child_models = @gen.child_models
131
- template_file = File.open(File.join(File.dirname(__FILE__), "/../lib/view_mapper/has_many_templates/view_#{template}.html.erb"))
131
+ template_file = File.open(@gen.source_path("view_#{template}.html.erb"))
132
132
  result = ERB.new(template_file.read, nil, '-').result(binding)
133
- expected_file = File.open(File.join(File.dirname(__FILE__), "expected_templates/has_many/#{template}.html.erb"))
133
+ expected_file = File.open(File.join(File.dirname(__FILE__), "expected_templates/#{template}.html.erb"))
134
134
  assert_equal expected_file.read, result
135
135
  end
136
136
  end
@@ -140,17 +140,17 @@ class HasManyViewTest < Test::Unit::TestCase
140
140
  @singular_name = @gen.singular_name
141
141
  @plural_name = @gen.plural_name
142
142
  @child_models = @gen.child_models
143
- template_file = File.open(File.join(File.dirname(__FILE__), "/../lib/view_mapper/has_many_templates/view_form.html.erb"))
143
+ template_file = File.open(@gen.source_path("view_form.html.erb"))
144
144
  result = ERB.new(template_file.read, nil, '-').result(binding)
145
- expected_file = File.open(File.join(File.dirname(__FILE__), "expected_templates/has_many/_form.html.erb"))
145
+ expected_file = File.open(File.join(File.dirname(__FILE__), "expected_templates/_form.html.erb"))
146
146
  assert_equal expected_file.read, result
147
147
  end
148
148
 
149
149
  should "render the person partial as expected" do
150
150
  @child_model = @gen.child_models[1]
151
- template_file = File.open(File.join(File.dirname(__FILE__), "/../lib/view_mapper/has_many_templates/view_child_form.html.erb"))
151
+ template_file = File.open(@gen.source_path("view_child_form.html.erb"))
152
152
  result = ERB.new(template_file.read, nil, '-').result(binding)
153
- expected_file = File.open(File.join(File.dirname(__FILE__), "expected_templates/has_many/_person.html.erb"))
153
+ expected_file = File.open(File.join(File.dirname(__FILE__), "expected_templates/_person.html.erb"))
154
154
  assert_equal expected_file.read, result
155
155
  end
156
156
  end
@@ -166,9 +166,9 @@ class HasManyViewTest < Test::Unit::TestCase
166
166
  @child_models = @gen.child_models
167
167
  @class_name = @gen.class_name
168
168
  @attributes = @gen.attributes
169
- template_file = File.open(File.join(File.dirname(__FILE__), "/../lib/view_mapper/has_many_templates/model.rb"))
169
+ template_file = File.open(@gen.source_path("model.rb"))
170
170
  result = ERB.new(template_file.read, nil, '-').result(binding)
171
- expected_file = File.open(File.join(File.dirname(__FILE__), "expected_templates/has_many/parent.rb"))
171
+ expected_file = File.open(File.join(File.dirname(__FILE__), "expected_templates/parent.rb"))
172
172
  assert_equal expected_file.read, result
173
173
  end
174
174
 
@@ -178,9 +178,9 @@ class HasManyViewTest < Test::Unit::TestCase
178
178
  @migration_name = 'CreateParents'
179
179
  @table_name = @gen.table_name
180
180
  @options = {}
181
- template_file = File.open(File.join(File.dirname(__FILE__), "/../lib/view_mapper/has_many_templates/migration.rb"))
181
+ template_file = File.open(@gen.source_path("migration.rb"))
182
182
  result = ERB.new(template_file.read, nil, '-').result(binding)
183
- expected_file = File.open(File.join(File.dirname(__FILE__), "expected_templates/has_many/create_parents.rb"))
183
+ expected_file = File.open(File.join(File.dirname(__FILE__), "expected_templates/create_parents.rb"))
184
184
  assert_equal expected_file.read, result
185
185
  end
186
186
  end
@@ -1,9 +1,10 @@
1
1
  class CreateTesties < ActiveRecord::Migration
2
2
  def self.up
3
3
  create_table :testies do |t|
4
- t.string :first_name
5
- t.string :last_name
6
- t.string :address
4
+ t.string :first_name
5
+ t.string :last_name
6
+ t.string :address
7
+ t.boolean :some_flag
7
8
  t.string :avatar_file_name
8
9
  t.string :avatar_content_type
9
10
  t.integer :avatar_file_size
@@ -14,6 +14,10 @@
14
14
  <%= f.label :address %><br />
15
15
  <%= f.text_field :address %>
16
16
  </p>
17
+ <p>
18
+ <%= f.label :some_flag %><br />
19
+ <%= f.check_box :some_flag %>
20
+ </p>
17
21
  <p>
18
22
  <%= f.label :avatar %><br />
19
23
  <%= f.file_field :avatar %>
@@ -0,0 +1,26 @@
1
+ <h1>Listing testies</h1>
2
+
3
+ <table>
4
+ <tr>
5
+ <th>First name</th>
6
+ <th>Last name</th>
7
+ <th>Address</th>
8
+ <th>Some flag</th>
9
+ </tr>
10
+
11
+ <% @testies.each do |testy| %>
12
+ <tr>
13
+ <td><%=h testy.first_name %></td>
14
+ <td><%=h testy.last_name %></td>
15
+ <td><%=h testy.address %></td>
16
+ <td><%=h testy.some_flag %></td>
17
+ <td><%= link_to 'Show', testy %></td>
18
+ <td><%= link_to 'Edit', edit_testy_path(testy) %></td>
19
+ <td><%= link_to 'Destroy', testy, :confirm => 'Are you sure?', :method => :delete %></td>
20
+ </tr>
21
+ <% end %>
22
+ </table>
23
+
24
+ <br />
25
+
26
+ <%= link_to 'New testy', new_testy_path %>
@@ -14,6 +14,10 @@
14
14
  <%= f.label :address %><br />
15
15
  <%= f.text_field :address %>
16
16
  </p>
17
+ <p>
18
+ <%= f.label :some_flag %><br />
19
+ <%= f.check_box :some_flag %>
20
+ </p>
17
21
  <p>
18
22
  <%= f.label :avatar %><br />
19
23
  <%= f.file_field :avatar %>
@@ -13,6 +13,11 @@
13
13
  <%=h @testy.address %>
14
14
  </p>
15
15
 
16
+ <p>
17
+ <b>Some flag:</b>
18
+ <%=h @testy.some_flag %>
19
+ </p>
20
+
16
21
  <p>
17
22
  <b>Avatar:</b>
18
23
  <%= link_to @testy.avatar_file_name, @testy.avatar.url %><br>
@@ -1,4 +1,4 @@
1
- require 'test_helper'
1
+ require File.dirname(__FILE__) + '/../../test_helper'
2
2
 
3
3
  class PaperclipViewTest < Test::Unit::TestCase
4
4
 
@@ -129,8 +129,16 @@ class PaperclipViewTest < Test::Unit::TestCase
129
129
  @gen = new_generator_for_test_model('view_for', ['--view', 'paperclip'])
130
130
  end
131
131
 
132
- should "return the proper source root folder" do
133
- assert_equal './test/../lib/view_mapper/paperclip_templates', @gen.source_root
132
+ should "return the proper source root" do
133
+ assert_equal File.expand_path(File.dirname(__FILE__) + '/../../..//lib/view_mapper/views/paperclip/templates'), ViewMapper::PaperclipView.source_root
134
+ end
135
+
136
+ should "have the proper value for source_roots_for_view" do
137
+ assert_equal [
138
+ File.expand_path(File.dirname(__FILE__) + '/../../..//lib/view_mapper/views/paperclip/templates'),
139
+ @gen.class.lookup('scaffold').path + '/templates',
140
+ @gen.class.lookup('model').path + '/templates'
141
+ ], @gen.source_roots_for_view
134
142
  end
135
143
 
136
144
  view_for_templates = %w{ new edit index show }
@@ -140,9 +148,9 @@ class PaperclipViewTest < Test::Unit::TestCase
140
148
  @singular_name = @gen.singular_name
141
149
  @plural_name = @gen.plural_name
142
150
  @attachments = @gen.attachments
143
- template_file = File.open(File.join(File.dirname(__FILE__), "/../lib/view_mapper/paperclip_templates/view_#{template}.html.erb"))
151
+ template_file = File.open(@gen.source_path("view_#{template}.html.erb"))
144
152
  result = ERB.new(template_file.read, nil, '-').result(binding)
145
- expected_file = File.open(File.join(File.dirname(__FILE__), "expected_templates/paperclip/#{template}.html.erb"))
153
+ expected_file = File.open(File.join(File.dirname(__FILE__), "expected_templates/#{template}.html.erb"))
146
154
  assert_equal expected_file.read, result
147
155
  end
148
156
  end
@@ -254,9 +262,9 @@ class PaperclipViewTest < Test::Unit::TestCase
254
262
  @class_name = @gen.class_name
255
263
  @attributes = @gen.attributes
256
264
  @attachments = @gen.attachments
257
- template_file = File.open(File.join(File.dirname(__FILE__), "/../lib/view_mapper/paperclip_templates/model.rb"))
265
+ template_file = File.open(@gen.source_path("model.rb"))
258
266
  result = ERB.new(template_file.read, nil, '-').result(binding)
259
- expected_file = File.open(File.join(File.dirname(__FILE__), "expected_templates/paperclip/testy.rb"))
267
+ expected_file = File.open(File.join(File.dirname(__FILE__), "expected_templates/testy.rb"))
260
268
  assert_equal expected_file.read, result
261
269
  end
262
270
 
@@ -267,9 +275,9 @@ class PaperclipViewTest < Test::Unit::TestCase
267
275
  @migration_name = 'CreateTesties'
268
276
  @table_name = @gen.table_name
269
277
  @options = {}
270
- template_file = File.open(File.join(File.dirname(__FILE__), "/../lib/view_mapper/paperclip_templates/migration.rb"))
278
+ template_file = File.open(@gen.source_path("migration.rb"))
271
279
  result = ERB.new(template_file.read, nil, '-').result(binding)
272
- expected_file = File.open(File.join(File.dirname(__FILE__), "expected_templates/paperclip/create_testies.rb"))
280
+ expected_file = File.open(File.join(File.dirname(__FILE__), "expected_templates/create_testies.rb"))
273
281
  assert_equal expected_file.read, result
274
282
  end
275
283
  end