giga-safe-tool 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/cocoon-1.2.15/Gemfile +33 -0
- data/cocoon-1.2.15/History.md +197 -0
- data/cocoon-1.2.15/LICENSE +20 -0
- data/cocoon-1.2.15/README.markdown +612 -0
- data/cocoon-1.2.15/Rakefile +89 -0
- data/cocoon-1.2.15/VERSION +1 -0
- data/cocoon-1.2.15/app/assets/javascripts/cocoon.js +146 -0
- data/cocoon-1.2.15/cocoon.gemspec +149 -0
- data/cocoon-1.2.15/gemfiles/Gemfile.default +31 -0
- data/cocoon-1.2.15/gemfiles/Gemfile.rails-3.2.13 +30 -0
- data/cocoon-1.2.15/gemfiles/Gemfile.rails-4-r2 +27 -0
- data/cocoon-1.2.15/lib/cocoon/view_helpers.rb +160 -0
- data/cocoon-1.2.15/lib/cocoon.rb +20 -0
- data/cocoon-1.2.15/lib/generators/cocoon/install/install_generator.rb +17 -0
- data/cocoon-1.2.15/npm/README.md +8 -0
- data/cocoon-1.2.15/npm/package.json.erb +21 -0
- data/cocoon-1.2.15/spec/cocoon_spec.rb +446 -0
- data/cocoon-1.2.15/spec/dummy/Rakefile +7 -0
- data/cocoon-1.2.15/spec/dummy/app/controllers/application_controller.rb +3 -0
- data/cocoon-1.2.15/spec/dummy/app/decorators/comment_decorator.rb +17 -0
- data/cocoon-1.2.15/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/cocoon-1.2.15/spec/dummy/app/models/comment.rb +7 -0
- data/cocoon-1.2.15/spec/dummy/app/models/person.rb +3 -0
- data/cocoon-1.2.15/spec/dummy/app/models/post.rb +9 -0
- data/cocoon-1.2.15/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/cocoon-1.2.15/spec/dummy/config/application.rb +45 -0
- data/cocoon-1.2.15/spec/dummy/config/boot.rb +10 -0
- data/cocoon-1.2.15/spec/dummy/config/database.yml +22 -0
- data/cocoon-1.2.15/spec/dummy/config/environment.rb +5 -0
- data/cocoon-1.2.15/spec/dummy/config/environments/development.rb +25 -0
- data/cocoon-1.2.15/spec/dummy/config/environments/production.rb +50 -0
- data/cocoon-1.2.15/spec/dummy/config/environments/test.rb +33 -0
- data/cocoon-1.2.15/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/cocoon-1.2.15/spec/dummy/config/initializers/inflections.rb +10 -0
- data/cocoon-1.2.15/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/cocoon-1.2.15/spec/dummy/config/initializers/rails_version_helper.rb +6 -0
- data/cocoon-1.2.15/spec/dummy/config/initializers/secret_token.rb +8 -0
- data/cocoon-1.2.15/spec/dummy/config/initializers/session_store.rb +8 -0
- data/cocoon-1.2.15/spec/dummy/config/locales/en.yml +5 -0
- data/cocoon-1.2.15/spec/dummy/config/routes.rb +58 -0
- data/cocoon-1.2.15/spec/dummy/config.ru +4 -0
- data/cocoon-1.2.15/spec/dummy/db/migrate/20110306212208_create_posts.rb +14 -0
- data/cocoon-1.2.15/spec/dummy/db/migrate/20110306212250_create_comments.rb +15 -0
- data/cocoon-1.2.15/spec/dummy/db/migrate/20110420222224_create_people.rb +15 -0
- data/cocoon-1.2.15/spec/dummy/db/schema.rb +39 -0
- data/cocoon-1.2.15/spec/dummy/public/404.html +26 -0
- data/cocoon-1.2.15/spec/dummy/public/422.html +26 -0
- data/cocoon-1.2.15/spec/dummy/public/500.html +26 -0
- data/cocoon-1.2.15/spec/dummy/public/favicon.ico +0 -0
- data/cocoon-1.2.15/spec/dummy/public/javascripts/application.js +2 -0
- data/cocoon-1.2.15/spec/dummy/public/javascripts/controls.js +965 -0
- data/cocoon-1.2.15/spec/dummy/public/javascripts/dragdrop.js +974 -0
- data/cocoon-1.2.15/spec/dummy/public/javascripts/effects.js +1123 -0
- data/cocoon-1.2.15/spec/dummy/public/javascripts/prototype.js +6001 -0
- data/cocoon-1.2.15/spec/dummy/public/javascripts/rails.js +175 -0
- data/cocoon-1.2.15/spec/dummy/script/rails +6 -0
- data/cocoon-1.2.15/spec/generators/install_generator_spec.rb +48 -0
- data/cocoon-1.2.15/spec/integration/navigation_spec.rb +9 -0
- data/cocoon-1.2.15/spec/spec_helper.rb +40 -0
- data/cocoon-1.2.15/spec/support/i18n.rb +3 -0
- data/cocoon-1.2.15/spec/support/rails_version_helper.rb +3 -0
- data/cocoon-1.2.15/spec/support/shared_examples.rb +73 -0
- data/giga-safe-tool.gemspec +11 -0
- metadata +103 -0
|
@@ -0,0 +1,446 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
require 'nokogiri'
|
|
3
|
+
|
|
4
|
+
describe Cocoon do
|
|
5
|
+
class TestClass < ActionView::Base
|
|
6
|
+
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
subject {TestClass.new}
|
|
10
|
+
|
|
11
|
+
it { is_expected.to respond_to(:link_to_add_association) }
|
|
12
|
+
it { is_expected.to respond_to(:link_to_remove_association) }
|
|
13
|
+
|
|
14
|
+
before(:each) do
|
|
15
|
+
@tester = TestClass.new
|
|
16
|
+
@post = Post.new
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
context "link_to_add_association" do
|
|
21
|
+
before(:each) do
|
|
22
|
+
@form_obj = double(:object => @post, :object_name => @post.class.name)
|
|
23
|
+
allow(@tester).to receive(:render_association).and_return('form<tag>')
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
context "without a block" do
|
|
27
|
+
|
|
28
|
+
context "and given a name" do
|
|
29
|
+
before do
|
|
30
|
+
@html = @tester.link_to_add_association('add something', @form_obj, :comments)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
it_behaves_like "a correctly rendered add link", {}
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
context 'and no name given' do
|
|
37
|
+
context 'custom translation exists' do
|
|
38
|
+
before do
|
|
39
|
+
I18n.backend.store_translations(:en, :cocoon => { :comments => { :add => 'Add comment' } })
|
|
40
|
+
|
|
41
|
+
@html = @tester.link_to_add_association(@form_obj, :comments)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
it_behaves_like "a correctly rendered add link", { text: 'Add comment' }
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
context 'uses default translation' do
|
|
48
|
+
before do
|
|
49
|
+
I18n.backend.store_translations(:en, :cocoon => { :defaults => { :add => 'Add' } })
|
|
50
|
+
|
|
51
|
+
@html = @tester.link_to_add_association(@form_obj, :comments)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
it_behaves_like "a correctly rendered add link", { text: 'Add' }
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
context "and given html options to pass them to link_to" do
|
|
59
|
+
before do
|
|
60
|
+
@html = @tester.link_to_add_association('add something', @form_obj, :comments, {:class => 'something silly'})
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
it_behaves_like "a correctly rendered add link", {class: 'something silly add_fields' }
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
context "and explicitly specifying the wanted partial" do
|
|
67
|
+
before do
|
|
68
|
+
allow(@tester).to receive(:render_association).and_call_original
|
|
69
|
+
expect(@tester).to receive(:render_association).with(anything(), anything(), anything(), "f", anything(), "shared/partial").and_return('partiallll')
|
|
70
|
+
@html = @tester.link_to_add_association('add something', @form_obj, :comments, :partial => "shared/partial")
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
it_behaves_like "a correctly rendered add link", {template: "partiallll"}
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
it "gives an opportunity to wrap/decorate created objects" do
|
|
77
|
+
allow(@tester).to receive(:render_association).and_call_original
|
|
78
|
+
expect(@tester).to receive(:render_association).with(anything(), anything(), kind_of(CommentDecorator), "f", anything(), anything()).and_return('partiallll')
|
|
79
|
+
@tester.link_to_add_association('add something', @form_obj, :comments, :wrap_object => Proc.new {|comment| CommentDecorator.new(comment) })
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
context "force non association create" do
|
|
83
|
+
context "default case: create object on association" do
|
|
84
|
+
before do
|
|
85
|
+
expect(@tester).to receive(:create_object).with(anything, :comments , false)
|
|
86
|
+
@html = @tester.link_to_add_association('add something', @form_obj, :comments)
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
it_behaves_like "a correctly rendered add link", {}
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
context "and explicitly specifying false is the same as default" do
|
|
93
|
+
before do
|
|
94
|
+
expect(@tester).to receive(:create_object).with(anything, :comments , false)
|
|
95
|
+
@html = @tester.link_to_add_association('add something', @form_obj, :comments, :force_non_association_create => false)
|
|
96
|
+
end
|
|
97
|
+
it_behaves_like "a correctly rendered add link", {}
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
context "specifying true will not create objects on association but using the conditions" do
|
|
101
|
+
before do
|
|
102
|
+
expect(@tester).to receive(:create_object).with(anything, :comments , true)
|
|
103
|
+
@html = @tester.link_to_add_association('add something', @form_obj, :comments, :force_non_association_create => true)
|
|
104
|
+
end
|
|
105
|
+
it_behaves_like "a correctly rendered add link", {}
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
context "with a block" do
|
|
111
|
+
context "and the block specifies the link text" do
|
|
112
|
+
before do
|
|
113
|
+
@html = @tester.link_to_add_association(@form_obj, :comments) do
|
|
114
|
+
"some long name"
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
it_behaves_like "a correctly rendered add link", {text: 'some long name'}
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
context "accepts html options and pass them to link_to" do
|
|
121
|
+
before do
|
|
122
|
+
@html = @tester.link_to_add_association(@form_obj, :comments, {:class => 'floppy disk'}) do
|
|
123
|
+
"some long name"
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
it_behaves_like "a correctly rendered add link", {class: 'floppy disk add_fields', text: 'some long name'}
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
context "accepts extra attributes and pass them to link_to" do
|
|
130
|
+
context 'when using the old notation' do
|
|
131
|
+
before do
|
|
132
|
+
@html = @tester.link_to_add_association(@form_obj, :comments, {:class => 'floppy disk', 'data-something' => 'bla'}) do
|
|
133
|
+
"some long name"
|
|
134
|
+
end
|
|
135
|
+
end
|
|
136
|
+
it_behaves_like "a correctly rendered add link", {class: 'floppy disk add_fields', text: 'some long name', :extra_attributes => {'data-something' => 'bla'}}
|
|
137
|
+
end
|
|
138
|
+
if Rails.rails4?
|
|
139
|
+
context 'when using the new notation' do
|
|
140
|
+
before do
|
|
141
|
+
@html = @tester.link_to_add_association(@form_obj, :comments, {:class => 'floppy disk', :data => {:'association-something' => 'foobar'}}) do
|
|
142
|
+
"some long name"
|
|
143
|
+
end
|
|
144
|
+
end
|
|
145
|
+
it_behaves_like "a correctly rendered add link", {class: 'floppy disk add_fields', text: 'some long name', :extra_attributes => {'data-association-something' => 'foobar'}}
|
|
146
|
+
end
|
|
147
|
+
end
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
context "and explicitly specifying the wanted partial" do
|
|
151
|
+
before do
|
|
152
|
+
allow(@tester).to receive(:render_association).and_call_original
|
|
153
|
+
expect(@tester).to receive(:render_association).with(anything(), anything(), anything(), "f", anything(), "shared/partial").and_return('partiallll')
|
|
154
|
+
@html = @tester.link_to_add_association( @form_obj, :comments, :class => 'floppy disk', :partial => "shared/partial") do
|
|
155
|
+
"some long name"
|
|
156
|
+
end
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
it_behaves_like "a correctly rendered add link", {class: 'floppy disk add_fields', template: "partiallll", text: 'some long name'}
|
|
160
|
+
end
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
context "with an irregular plural" do
|
|
164
|
+
context "uses the correct plural" do
|
|
165
|
+
before do
|
|
166
|
+
@html = @tester.link_to_add_association('add something', @form_obj, :people)
|
|
167
|
+
end
|
|
168
|
+
it_behaves_like "a correctly rendered add link", {association: 'person', associations: 'people' }
|
|
169
|
+
end
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
context "when using aliased association and class-name" do
|
|
173
|
+
context "uses the correct name" do
|
|
174
|
+
before do
|
|
175
|
+
@html = @tester.link_to_add_association('add something', @form_obj, :admin_comments)
|
|
176
|
+
end
|
|
177
|
+
it_behaves_like "a correctly rendered add link", {association: 'admin_comment', associations: 'admin_comments'}
|
|
178
|
+
end
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
it "tttt" do
|
|
182
|
+
expect(@post.class.reflect_on_association(:people).klass.new).to be_a(Person)
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
context "with extra render-options for rendering the child relation" do
|
|
186
|
+
context "uses the correct plural" do
|
|
187
|
+
before do
|
|
188
|
+
expect(@tester).to receive(:render_association).with(:people, @form_obj, anything, "f", {:wrapper => 'inline'}, nil)
|
|
189
|
+
@html = @tester.link_to_add_association('add something', @form_obj, :people, :render_options => {:wrapper => 'inline'})
|
|
190
|
+
end
|
|
191
|
+
it_behaves_like "a correctly rendered add link", {association: 'person', associations: 'people' }
|
|
192
|
+
end
|
|
193
|
+
end
|
|
194
|
+
|
|
195
|
+
context "passing locals to the partial" do
|
|
196
|
+
context "when given: passes the locals to the partials" do
|
|
197
|
+
before do
|
|
198
|
+
allow(@tester).to receive(:render_association).and_call_original
|
|
199
|
+
expect(@form_obj).to receive(:fields_for) { | association, new_object, options_hash, &block| block.call }
|
|
200
|
+
expect(@tester).to receive(:render).with("person_fields", {:f=>nil, :dynamic=>true, :alfred=>"Judoka"}).and_return ("partiallll")
|
|
201
|
+
@render_options = {:wrapper => 'inline', :locals => {:alfred => 'Judoka'}}
|
|
202
|
+
@html = @tester.link_to_add_association('add something', @form_obj, :people, :render_options => @render_options)
|
|
203
|
+
end
|
|
204
|
+
it_behaves_like "a correctly rendered add link", {template: 'partiallll', association: 'person', associations: 'people' }
|
|
205
|
+
it "does not afffect render-options" do
|
|
206
|
+
expect(@render_options[:locals]).to eq({alfred: 'Judoka'})
|
|
207
|
+
end
|
|
208
|
+
end
|
|
209
|
+
context "if no locals are given it still works" do
|
|
210
|
+
before do
|
|
211
|
+
allow(@tester).to receive(:render_association).and_call_original
|
|
212
|
+
expect(@form_obj).to receive(:fields_for) { | association, new_object, options_hash, &block| block.call }
|
|
213
|
+
expect(@tester).to receive(:render).with("person_fields", {:f=>nil, :dynamic=>true}).and_return ("partiallll")
|
|
214
|
+
@html = @tester.link_to_add_association('add something', @form_obj, :people, :render_options => {:wrapper => 'inline'})
|
|
215
|
+
end
|
|
216
|
+
it_behaves_like "a correctly rendered add link", {template: 'partiallll', association: 'person', associations: 'people' }
|
|
217
|
+
|
|
218
|
+
#result.to_s.should == '<a href="#" class="add_fields" data-association-insertion-template="partiallll" data-association="person" data-associations="people">add something</a>'
|
|
219
|
+
end
|
|
220
|
+
end
|
|
221
|
+
|
|
222
|
+
context "overruling the form parameter name" do
|
|
223
|
+
context "when given a form_name it passes it correctly to the partials" do
|
|
224
|
+
before do
|
|
225
|
+
allow(@tester).to receive(:render_association).and_call_original
|
|
226
|
+
expect(@form_obj).to receive(:fields_for) { | association, new_object, options_hash, &block| block.call }
|
|
227
|
+
expect(@tester).to receive(:render).with("person_fields", {:people_form => nil, :dynamic=>true}).and_return ("partiallll")
|
|
228
|
+
@html = @tester.link_to_add_association('add something', @form_obj, :people, :form_name => 'people_form')
|
|
229
|
+
end
|
|
230
|
+
it_behaves_like "a correctly rendered add link", {template: 'partiallll', association: 'person', associations: 'people' }
|
|
231
|
+
end
|
|
232
|
+
end
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
context "when using formtastic" do
|
|
236
|
+
before(:each) do
|
|
237
|
+
allow(@tester).to receive(:render_association).and_call_original
|
|
238
|
+
allow(@form_obj).to receive(:semantic_fields_for).and_return('form<tagzzz>')
|
|
239
|
+
end
|
|
240
|
+
context "calls semantic_fields_for and not fields_for" do
|
|
241
|
+
before do
|
|
242
|
+
allow(@form_obj).to receive_message_chain(:class, :ancestors) { ['Formtastic::FormBuilder'] }
|
|
243
|
+
expect(@form_obj).to receive(:semantic_fields_for)
|
|
244
|
+
expect(@form_obj).to receive(:fields_for).never
|
|
245
|
+
@html = @tester.link_to_add_association('add something', @form_obj, :people)
|
|
246
|
+
end
|
|
247
|
+
it_behaves_like "a correctly rendered add link", {template: 'form<tagzzz>', association: 'person', associations: 'people' }
|
|
248
|
+
end
|
|
249
|
+
end
|
|
250
|
+
context "when using simple_form" do
|
|
251
|
+
before(:each) do
|
|
252
|
+
allow(@tester).to receive(:render_association).and_call_original
|
|
253
|
+
allow(@form_obj).to receive(:simple_fields_for).and_return('form<tagxxx>')
|
|
254
|
+
end
|
|
255
|
+
it "responds_to :simple_fields_for" do
|
|
256
|
+
expect(@form_obj).to respond_to(:simple_fields_for)
|
|
257
|
+
end
|
|
258
|
+
context "calls simple_fields_for and not fields_for" do
|
|
259
|
+
before do
|
|
260
|
+
allow(@form_obj).to receive_message_chain(:class, :ancestors) { ['SimpleForm::FormBuilder'] }
|
|
261
|
+
expect(@form_obj).to receive(:simple_fields_for)
|
|
262
|
+
expect(@form_obj).to receive(:fields_for).never
|
|
263
|
+
@html = @tester.link_to_add_association('add something', @form_obj, :people)
|
|
264
|
+
end
|
|
265
|
+
it_behaves_like "a correctly rendered add link", {template: 'form<tagxxx>', association: 'person', associations: 'people' }
|
|
266
|
+
end
|
|
267
|
+
end
|
|
268
|
+
|
|
269
|
+
context 'when adding a count' do
|
|
270
|
+
before do
|
|
271
|
+
@html = @tester.link_to_add_association('add something', @form_obj, :comments, { :count => 3 })
|
|
272
|
+
end
|
|
273
|
+
it_behaves_like "a correctly rendered add link", { :extra_attributes => { 'data-count' => '3' } }
|
|
274
|
+
end
|
|
275
|
+
|
|
276
|
+
end
|
|
277
|
+
|
|
278
|
+
context "link_to_remove_association" do
|
|
279
|
+
before do
|
|
280
|
+
@form_obj = @tester.send(:instantiate_builder, @post.class.name, @post, {})
|
|
281
|
+
end
|
|
282
|
+
context "without a block" do
|
|
283
|
+
context "accepts a name" do
|
|
284
|
+
before do
|
|
285
|
+
@html = @tester.link_to_remove_association('remove something', @form_obj)
|
|
286
|
+
end
|
|
287
|
+
|
|
288
|
+
it "is rendered inside a input element" do
|
|
289
|
+
doc = Nokogiri::HTML(@html)
|
|
290
|
+
removed = doc.at('input')
|
|
291
|
+
expect(removed.attribute('id').value).to eq("Post__destroy")
|
|
292
|
+
expect(removed.attribute('name').value).to eq("Post[_destroy]")
|
|
293
|
+
expect(removed.attribute('value').value).to eq("false")
|
|
294
|
+
end
|
|
295
|
+
|
|
296
|
+
it_behaves_like "a correctly rendered remove link", {}
|
|
297
|
+
end
|
|
298
|
+
|
|
299
|
+
context 'no name given' do
|
|
300
|
+
context 'custom translation exists' do
|
|
301
|
+
before do
|
|
302
|
+
I18n.backend.store_translations(:en, :cocoon => { :posts => { :remove => 'Remove post' } })
|
|
303
|
+
|
|
304
|
+
@html = @tester.link_to_remove_association(@form_obj)
|
|
305
|
+
end
|
|
306
|
+
|
|
307
|
+
it_behaves_like "a correctly rendered remove link", { text: 'Remove post' }
|
|
308
|
+
end
|
|
309
|
+
|
|
310
|
+
context 'uses default translation' do
|
|
311
|
+
before do
|
|
312
|
+
I18n.backend.store_translations(:en, :cocoon => { :defaults => { :remove => 'Remove' } })
|
|
313
|
+
|
|
314
|
+
@html = @tester.link_to_remove_association(@form_obj)
|
|
315
|
+
end
|
|
316
|
+
|
|
317
|
+
it_behaves_like "a correctly rendered remove link", { text: 'Remove' }
|
|
318
|
+
end
|
|
319
|
+
end
|
|
320
|
+
|
|
321
|
+
context "accepts html options and pass them to link_to" do
|
|
322
|
+
before do
|
|
323
|
+
@html = @tester.link_to_remove_association('remove something', @form_obj, {:class => 'add_some_class', :'data-something' => 'bla'})
|
|
324
|
+
end
|
|
325
|
+
it_behaves_like "a correctly rendered remove link", {class: 'add_some_class remove_fields dynamic', extra_attributes: {'data-something' => 'bla'}}
|
|
326
|
+
end
|
|
327
|
+
|
|
328
|
+
end
|
|
329
|
+
|
|
330
|
+
# this is needed when due to some validation error, objects that
|
|
331
|
+
# were already marked for destruction need to remain hidden
|
|
332
|
+
context "for a object marked for destruction" do
|
|
333
|
+
before do
|
|
334
|
+
@post_marked_for_destruction = Post.new
|
|
335
|
+
@post_marked_for_destruction.mark_for_destruction
|
|
336
|
+
@form_obj_destroyed = @tester.send(:instantiate_builder, @post_marked_for_destruction.class.name, @post_marked_for_destruction, {})
|
|
337
|
+
@html = @tester.link_to_remove_association('remove something', @form_obj_destroyed)
|
|
338
|
+
end
|
|
339
|
+
|
|
340
|
+
it "is rendered inside a input element" do
|
|
341
|
+
doc = Nokogiri::HTML(@html)
|
|
342
|
+
removed = doc.at('input')
|
|
343
|
+
expect(removed.attribute('id').value).to eq("Post__destroy")
|
|
344
|
+
expect(removed.attribute('name').value).to eq("Post[_destroy]")
|
|
345
|
+
expect(removed.attribute('value').value).to eq("true")
|
|
346
|
+
end
|
|
347
|
+
|
|
348
|
+
it_behaves_like "a correctly rendered remove link", {class: 'remove_fields dynamic destroyed'}
|
|
349
|
+
end
|
|
350
|
+
|
|
351
|
+
context "with a block" do
|
|
352
|
+
context "the block gives the name" do
|
|
353
|
+
before do
|
|
354
|
+
@html = @tester.link_to_remove_association(@form_obj) do
|
|
355
|
+
"remove some long name"
|
|
356
|
+
end
|
|
357
|
+
end
|
|
358
|
+
it_behaves_like "a correctly rendered remove link", {text: 'remove some long name'}
|
|
359
|
+
end
|
|
360
|
+
|
|
361
|
+
context "accepts html options and pass them to link_to" do
|
|
362
|
+
before do
|
|
363
|
+
@html = @tester.link_to_remove_association(@form_obj, {:class => 'add_some_class', :'data-something' => 'bla'}) do
|
|
364
|
+
"remove some long name"
|
|
365
|
+
end
|
|
366
|
+
end
|
|
367
|
+
it_behaves_like "a correctly rendered remove link", {text: 'remove some long name', class: 'add_some_class remove_fields dynamic', extra_attributes: {'data-something' => 'bla'}}
|
|
368
|
+
end
|
|
369
|
+
end
|
|
370
|
+
|
|
371
|
+
context 'when changing the wrapper class' do
|
|
372
|
+
context 'should use the default nested-fields class' do
|
|
373
|
+
before do
|
|
374
|
+
@html = @tester.link_to_remove_association('remove something', @form_obj)
|
|
375
|
+
end
|
|
376
|
+
|
|
377
|
+
it_behaves_like "a correctly rendered remove link", { }
|
|
378
|
+
end
|
|
379
|
+
|
|
380
|
+
context 'should use the given wrapper class' do
|
|
381
|
+
before do
|
|
382
|
+
@html = @tester.link_to_remove_association('remove something', @form_obj, { wrapper_class: 'another-class' })
|
|
383
|
+
end
|
|
384
|
+
|
|
385
|
+
it_behaves_like "a correctly rendered remove link", { extra_attributes: { 'data-wrapper-class' => 'another-class' } }
|
|
386
|
+
end
|
|
387
|
+
end
|
|
388
|
+
end
|
|
389
|
+
|
|
390
|
+
context "create_object" do
|
|
391
|
+
it "creates correct association with conditions" do
|
|
392
|
+
expect(@tester).not_to receive(:create_object_with_conditions)
|
|
393
|
+
# in rails4 we cannot create an associated object when the object has not been saved before
|
|
394
|
+
# I submitted a bug for this: https://github.com/rails/rails/issues/11376
|
|
395
|
+
if Rails.rails4?
|
|
396
|
+
@post = Post.create(title: 'Testing')
|
|
397
|
+
end
|
|
398
|
+
form_obj = double(:object => @post, :object_name => @post.class.name)
|
|
399
|
+
result = @tester.create_object(form_obj, :admin_comments)
|
|
400
|
+
expect(result.author).to eq("Admin")
|
|
401
|
+
expect(form_obj.object.admin_comments).to be_empty
|
|
402
|
+
end
|
|
403
|
+
|
|
404
|
+
it "creates correct association for belongs_to associations" do
|
|
405
|
+
comment = Comment.new
|
|
406
|
+
form_obj = double(:object => Comment.new)
|
|
407
|
+
result = @tester.create_object(form_obj, :post)
|
|
408
|
+
expect(result).to be_a Post
|
|
409
|
+
expect(comment.post).to be_nil
|
|
410
|
+
end
|
|
411
|
+
|
|
412
|
+
it "raises an error if cannot reflect on association" do
|
|
413
|
+
expect { @tester.create_object(double(:object => Comment.new), :not_existing) }.to raise_error /association/i
|
|
414
|
+
end
|
|
415
|
+
|
|
416
|
+
it "creates an association if object responds to 'build_association' as singular" do
|
|
417
|
+
object = Comment.new
|
|
418
|
+
expect(object).to receive(:build_custom_item).and_return 'custom'
|
|
419
|
+
expect(@tester.create_object(double(:object => object), :custom_item)).to eq('custom')
|
|
420
|
+
end
|
|
421
|
+
|
|
422
|
+
it "creates an association if object responds to 'build_association' as plural" do
|
|
423
|
+
object = Comment.new
|
|
424
|
+
expect(object).to receive(:build_custom_item).and_return 'custom'
|
|
425
|
+
expect(@tester.create_object(double(:object => object), :custom_items)).to eq('custom')
|
|
426
|
+
end
|
|
427
|
+
|
|
428
|
+
it "can create using only conditions not the association" do
|
|
429
|
+
expect(@tester).to receive(:create_object_with_conditions).and_return('flappie')
|
|
430
|
+
form_obj = @tester.send(:instantiate_builder, @post.class.name, @post, {})
|
|
431
|
+
expect(@tester.create_object(form_obj, :comments, true)).to eq('flappie')
|
|
432
|
+
end
|
|
433
|
+
end
|
|
434
|
+
|
|
435
|
+
context "get_partial_path" do
|
|
436
|
+
it "generates the default partial name if no partial given" do
|
|
437
|
+
result = @tester.get_partial_path(nil, :admin_comments)
|
|
438
|
+
expect(result).to eq("admin_comment_fields")
|
|
439
|
+
end
|
|
440
|
+
it "uses the given partial name" do
|
|
441
|
+
result = @tester.get_partial_path("comment_fields", :admin_comments)
|
|
442
|
+
expect(result).to eq("comment_fields")
|
|
443
|
+
end
|
|
444
|
+
end
|
|
445
|
+
|
|
446
|
+
end
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# Add your own tasks in files placed in lib/tasks ending in .rake,
|
|
2
|
+
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
|
|
3
|
+
|
|
4
|
+
require File.expand_path('../config/application', __FILE__)
|
|
5
|
+
require 'rake'
|
|
6
|
+
|
|
7
|
+
Dummy::Application.load_tasks
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
class CommentDecorator
|
|
2
|
+
def initialize(comment)
|
|
3
|
+
@comment = comment
|
|
4
|
+
end
|
|
5
|
+
|
|
6
|
+
def formatted_created_at
|
|
7
|
+
@comment.created_at.to_formatted_s(:short)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def method_missing(method_sym, *args)
|
|
11
|
+
if @comment.respond_to?(method_sym)
|
|
12
|
+
@comment.send(method_sym, *args)
|
|
13
|
+
else
|
|
14
|
+
super
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
class Post < ActiveRecord::Base
|
|
2
|
+
has_many :comments
|
|
3
|
+
if Rails.rails4?
|
|
4
|
+
has_many :admin_comments, -> { where author: "Admin" }, :class_name => "Comment"
|
|
5
|
+
else
|
|
6
|
+
has_many :admin_comments, :class_name => "Comment", :conditions => { :author => "Admin" }
|
|
7
|
+
end
|
|
8
|
+
has_many :people
|
|
9
|
+
end
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
require File.expand_path('../boot', __FILE__)
|
|
2
|
+
|
|
3
|
+
require "active_model/railtie"
|
|
4
|
+
require "active_record/railtie"
|
|
5
|
+
require "action_controller/railtie"
|
|
6
|
+
require "action_view/railtie"
|
|
7
|
+
require "action_mailer/railtie"
|
|
8
|
+
|
|
9
|
+
Bundler.require
|
|
10
|
+
require "cocoon"
|
|
11
|
+
|
|
12
|
+
module Dummy
|
|
13
|
+
class Application < Rails::Application
|
|
14
|
+
# Settings in config/environments/* take precedence over those specified here.
|
|
15
|
+
# Application configuration should go into files in config/initializers
|
|
16
|
+
# -- all .rb files in that directory are automatically loaded.
|
|
17
|
+
|
|
18
|
+
# Custom directories with classes and modules you want to be autoloadable.
|
|
19
|
+
# config.autoload_paths += %W(#{config.root}/extras)
|
|
20
|
+
|
|
21
|
+
# Only load the plugins named here, in the order given (default is alphabetical).
|
|
22
|
+
# :all can be used as a placeholder for all plugins not explicitly named.
|
|
23
|
+
# config.plugins = [ :exception_notification, :ssl_requirement, :all ]
|
|
24
|
+
|
|
25
|
+
# Activate observers that should always be running.
|
|
26
|
+
# config.active_record.observers = :cacher, :garbage_collector, :forum_observer
|
|
27
|
+
|
|
28
|
+
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
|
|
29
|
+
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
|
|
30
|
+
# config.time_zone = 'Central Time (US & Canada)'
|
|
31
|
+
|
|
32
|
+
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
|
|
33
|
+
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
|
|
34
|
+
# config.i18n.default_locale = :de
|
|
35
|
+
|
|
36
|
+
# JavaScript files you want as :defaults (application.js is always included).
|
|
37
|
+
# config.action_view.javascript_expansions[:defaults] = %w(jquery rails)
|
|
38
|
+
|
|
39
|
+
# Configure the default encoding used in templates for Ruby 1.9.
|
|
40
|
+
config.encoding = "utf-8"
|
|
41
|
+
|
|
42
|
+
# Configure sensitive parameters which will be filtered from the log file.
|
|
43
|
+
config.filter_parameters += [:password]
|
|
44
|
+
end
|
|
45
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# SQLite version 3.x
|
|
2
|
+
# gem install sqlite3-ruby (not necessary on OS X Leopard)
|
|
3
|
+
development:
|
|
4
|
+
adapter: sqlite3
|
|
5
|
+
database: db/development.sqlite3
|
|
6
|
+
pool: 5
|
|
7
|
+
timeout: 5000
|
|
8
|
+
|
|
9
|
+
# Warning: The database defined as "test" will be erased and
|
|
10
|
+
# re-generated from your development database when you run "rake".
|
|
11
|
+
# Do not set this db to the same as development or production.
|
|
12
|
+
test:
|
|
13
|
+
adapter: sqlite3
|
|
14
|
+
database: db/test.sqlite3
|
|
15
|
+
pool: 5
|
|
16
|
+
timeout: 5000
|
|
17
|
+
|
|
18
|
+
production:
|
|
19
|
+
adapter: sqlite3
|
|
20
|
+
database: db/production.sqlite3
|
|
21
|
+
pool: 5
|
|
22
|
+
timeout: 5000
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
Dummy::Application.configure do
|
|
2
|
+
# Settings specified here will take precedence over those in config/application.rb
|
|
3
|
+
|
|
4
|
+
# In the development environment your application's code is reloaded on
|
|
5
|
+
# every request. This slows down response time but is perfect for development
|
|
6
|
+
# since you don't have to restart the webserver when you make code changes.
|
|
7
|
+
config.cache_classes = false
|
|
8
|
+
|
|
9
|
+
config.eager_load = false
|
|
10
|
+
|
|
11
|
+
# Show full error reports and disable caching
|
|
12
|
+
config.consider_all_requests_local = true
|
|
13
|
+
#config.action_view.debug_rjs = true
|
|
14
|
+
config.action_controller.perform_caching = false
|
|
15
|
+
|
|
16
|
+
# Don't care if the mailer can't send
|
|
17
|
+
config.action_mailer.raise_delivery_errors = false
|
|
18
|
+
|
|
19
|
+
# Print deprecation notices to the Rails logger
|
|
20
|
+
config.active_support.deprecation = :log
|
|
21
|
+
|
|
22
|
+
# Only use best-standards-support built into browsers
|
|
23
|
+
config.action_dispatch.best_standards_support = :builtin
|
|
24
|
+
end
|
|
25
|
+
|