constructor-pages 1.0.0beta1 → 1.0.0beta2

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.
Files changed (64) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/constructor_pages/urlify.js +1 -0
  3. data/app/controllers/constructor_pages/fields_controller.rb +22 -28
  4. data/app/controllers/constructor_pages/pages_controller.rb +19 -48
  5. data/app/controllers/constructor_pages/templates_controller.rb +8 -20
  6. data/app/helpers/constructor_pages/fields_helper.rb +0 -2
  7. data/app/helpers/constructor_pages/pages_helper.rb +2 -9
  8. data/app/models/constructor_pages/field.rb +24 -10
  9. data/app/models/constructor_pages/page.rb +10 -13
  10. data/app/models/constructor_pages/template.rb +5 -4
  11. data/app/models/constructor_pages/types/boolean_type.rb +0 -2
  12. data/app/models/constructor_pages/types/date_type.rb +0 -2
  13. data/app/models/constructor_pages/types/float_type.rb +0 -2
  14. data/app/models/constructor_pages/types/html_type.rb +0 -2
  15. data/app/models/constructor_pages/types/image_type.rb +0 -2
  16. data/app/models/constructor_pages/types/integer_type.rb +0 -2
  17. data/app/models/constructor_pages/types/string_type.rb +0 -2
  18. data/app/models/constructor_pages/types/text_type.rb +0 -2
  19. data/app/views/constructor_pages/fields/_form.html.slim +4 -4
  20. data/app/views/constructor_pages/fields/types/_boolean.html.slim +1 -0
  21. data/app/views/constructor_pages/fields/types/_html.html.slim +1 -1
  22. data/app/views/constructor_pages/fields/types/_string.html.slim +1 -1
  23. data/app/views/constructor_pages/fields/types/_text.html.slim +1 -1
  24. data/app/views/constructor_pages/pages/_form.html.slim +5 -8
  25. data/app/views/constructor_pages/pages/index.html.slim +2 -3
  26. data/app/views/constructor_pages/templates/_form.html.slim +0 -4
  27. data/config/locales/en.yml +2 -0
  28. data/config/locales/fr.yml +2 -0
  29. data/config/locales/ru.yml +2 -0
  30. data/config/routes.rb +1 -1
  31. data/constructor-pages.gemspec +1 -2
  32. data/db/migrate/10_create_html_types.rb +1 -5
  33. data/db/migrate/11_create_image_types.rb +1 -5
  34. data/db/migrate/12_add_default_template.rb +3 -3
  35. data/db/migrate/14_remove_child_id_from_templates.rb +2 -6
  36. data/db/migrate/15_rename_link_to_redirect.rb +1 -5
  37. data/db/migrate/16_add_indexes.rb +13 -0
  38. data/db/migrate/1_create_pages.rb +12 -16
  39. data/db/migrate/2_create_templates.rb +1 -5
  40. data/db/migrate/3_create_fields.rb +1 -5
  41. data/db/migrate/4_create_string_types.rb +2 -6
  42. data/db/migrate/5_create_float_types.rb +2 -6
  43. data/db/migrate/6_create_boolean_types.rb +2 -6
  44. data/db/migrate/7_create_integer_types.rb +2 -6
  45. data/db/migrate/8_create_text_types.rb +1 -5
  46. data/db/migrate/9_create_date_types.rb +2 -6
  47. data/lib/constructor-pages.rb +1 -0
  48. data/spec/features/constructor_pages/fields_spec.rb +5 -6
  49. data/spec/features/constructor_pages/pages_spec.rb +26 -63
  50. data/spec/features/constructor_pages/templates_spec.rb +15 -28
  51. data/spec/models/constructor_pages/field_spec.rb +0 -2
  52. data/spec/models/constructor_pages/page_spec.rb +15 -31
  53. data/spec/models/constructor_pages/template_spec.rb +0 -2
  54. data/spec/models/constructor_pages/types/boolean_type_spec.rb +0 -2
  55. data/spec/models/constructor_pages/types/date_type_spec.rb +0 -2
  56. data/spec/models/constructor_pages/types/float_type_spec.rb +0 -5
  57. data/spec/models/constructor_pages/types/html_type_spec.rb +0 -2
  58. data/spec/models/constructor_pages/types/integer_type_spec.rb +0 -2
  59. data/spec/models/constructor_pages/types/string_type_spec.rb +0 -2
  60. data/spec/models/constructor_pages/types/text_type_spec.rb +0 -2
  61. metadata +19 -7
  62. data/app/helpers/constructor_pages/code_name_uniq.rb +0 -7
  63. data/app/helpers/constructor_pages/for_select.rb +0 -13
  64. data/app/helpers/constructor_pages/templates_helper.rb +0 -5
@@ -1,5 +1,5 @@
1
1
  class CreateTextTypes < ActiveRecord::Migration
2
- def self.up
2
+ def change
3
3
  create_table ConstructorPages::Types::TextType.table_name do |t|
4
4
  t.text :value
5
5
  t.references :field
@@ -8,8 +8,4 @@ class CreateTextTypes < ActiveRecord::Migration
8
8
  t.timestamps
9
9
  end
10
10
  end
11
-
12
- def self.down
13
- drop_table ConstructorPages::Types::TextType.table_name
14
- end
15
11
  end
@@ -1,15 +1,11 @@
1
1
  class CreateDateTypes < ActiveRecord::Migration
2
- def self.up
2
+ def change
3
3
  create_table ConstructorPages::Types::DateType.table_name do |t|
4
- t.date :value, :default => Time.now
4
+ t.date :value, default: Time.now
5
5
  t.references :field
6
6
  t.references :page
7
7
 
8
8
  t.timestamps
9
9
  end
10
10
  end
11
-
12
- def self.down
13
- drop_table ConstructorPages::Types::DateType.table_name
14
- end
15
11
  end
@@ -1,5 +1,6 @@
1
1
  require 'awesome_nested_set'
2
2
  require 'slim'
3
+ require 'activerecord-import'
3
4
  require 'constructor_pages/engine'
4
5
  require 'rack/cache'
5
6
  require 'acts_as_list'
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  require 'spec_helper'
4
2
 
5
3
  module ConstructorPages
@@ -19,6 +17,7 @@ module ConstructorPages
19
17
  end
20
18
 
21
19
  @template = Template.create name: 'Page', code_name: 'page'
20
+ @page = Page.create name: 'Page'
22
21
 
23
22
  login_as @user
24
23
  end
@@ -55,13 +54,13 @@ module ConstructorPages
55
54
  end
56
55
 
57
56
  context 'Access' do
58
- it 'should be accessed by new_field_path if loggen in' do
57
+ it 'should be accessed by new_field_path if logged in' do
59
58
  visit pages.new_template_field_path(@template)
60
59
  current_path.should == pages.new_template_field_path(@template)
61
60
  status_code.should == 200
62
61
  end
63
62
 
64
- it 'should not be accessed by new_field_path if not loggen in' do
63
+ it 'should not be accessed by new_field_path if not logged in' do
65
64
  logout
66
65
  visit pages.new_template_field_path(@template)
67
66
  current_path.should == '/'
@@ -156,13 +155,13 @@ module ConstructorPages
156
155
  end
157
156
 
158
157
  context 'Access' do
159
- it 'should be accessed by edit_field_path if loggen in' do
158
+ it 'should be accessed by edit_field_path if logged in' do
160
159
  visit pages.edit_template_field_path(@template, @field_content)
161
160
  current_path.should == pages.edit_template_field_path(@template, @field_content)
162
161
  status_code.should == 200
163
162
  end
164
163
 
165
- it 'should not be accessed by new_field_path if not loggen in' do
164
+ it 'should not be accessed by edit_field_path if not logged in' do
166
165
  logout
167
166
  visit pages.edit_template_field_path(@template, @field_content)
168
167
  current_path.should == '/'
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  require 'spec_helper'
4
2
 
5
3
  module ConstructorPages
@@ -19,6 +17,7 @@ module ConstructorPages
19
17
  end
20
18
 
21
19
  @template = Template.create name: 'Page', code_name: 'page'
20
+ @page = Page.create name: 'Page'
22
21
 
23
22
  login_as @user
24
23
  end
@@ -38,19 +37,6 @@ module ConstructorPages
38
37
  end
39
38
  end
40
39
 
41
- it 'should notice if no template exists' do
42
- Template.delete_all
43
- visit pages.pages_path
44
- page.should_not have_link 'New page'
45
- page.should have_content 'Create at least one template'
46
- end
47
-
48
- it 'should not notice if template exists' do
49
- visit pages.pages_path
50
- page.should have_link 'New page'
51
- page.should_not have_text 'Create at least one template'
52
- end
53
-
54
40
  it 'should has pages list' do
55
41
  Page.create name: 'Zanussi'
56
42
  visit pages.pages_path
@@ -86,6 +72,8 @@ module ConstructorPages
86
72
  it 'should redirect if redirect specified' do
87
73
  _page = Page.create name: 'First page', template: @template
88
74
  _template = Template.create name: 'Home page', code_name: 'home_page'
75
+ _second_page = Page.create name: 'Second page', template: _template
76
+ _third_page = Page.create name: 'Third page', template: _template
89
77
 
90
78
  visit _page.full_url
91
79
  current_path.should == '/first-page'
@@ -120,6 +108,13 @@ module ConstructorPages
120
108
  end
121
109
  end
122
110
 
111
+ it 'should redirect if no template exist' do
112
+ Template.delete_all
113
+ visit pages.new_page_path
114
+ current_path.should == pages.pages_path
115
+ page.should have_text 'You need create at least one template'
116
+ end
117
+
123
118
  it 'should has published checkbox' do
124
119
  visit pages.new_page_path
125
120
  page.should have_checked_field 'Active'
@@ -135,6 +130,11 @@ module ConstructorPages
135
130
  page.should_not have_link 'Delete'
136
131
  end
137
132
 
133
+ it 'should has template select' do
134
+ visit pages.new_page_path
135
+ page.should have_select 'Template'
136
+ end
137
+
138
138
  it 'should has create button' do
139
139
  visit pages.new_page_path
140
140
  page.should have_button 'Create Page'
@@ -143,12 +143,13 @@ module ConstructorPages
143
143
  it 'should save new page' do
144
144
  visit pages.new_page_path
145
145
  fill_in 'Name', with: 'Hello world'
146
- Page.count.should == 0
147
146
  click_button 'Create Page'
148
- Page.count.should == 1
149
- _page = Page.first
147
+ Page.count.should == 2
148
+
149
+ _page = Page.last
150
150
  _page.name.should == 'Hello world'
151
151
  _page.url.should == 'hello-world'
152
+
152
153
  current_path.should == pages.pages_path
153
154
  page.should have_text 'added successfully'
154
155
  end
@@ -172,21 +173,14 @@ module ConstructorPages
172
173
  end
173
174
  end
174
175
 
175
- it 'should edit with template view' do
176
+ it 'should has delete link' do
176
177
  visit pages.edit_page_path(@page)
177
- page.should have_content 'This page show edit with template'
178
- end
179
-
180
- it 'should edit with page view if no view found' do
181
- _template = Template.create name: 'Hello', code_name: 'hello'
182
- _page = Page.create name: 'Hello', template: _template
183
- visit pages.edit_page_path(_page)
184
- page.should_not have_content 'This page show edit with template'
178
+ page.should have_link 'Delete'
185
179
  end
186
180
 
187
- it 'should has delete link' do
181
+ it 'should not has template select' do
188
182
  visit pages.edit_page_path(@page)
189
- page.should have_link 'Delete'
183
+ page.should_not have_select 'Template'
190
184
  end
191
185
 
192
186
  it 'should edit page' do
@@ -211,9 +205,9 @@ module ConstructorPages
211
205
  it 'should delete from page' do
212
206
  _page = Page.create name: 'Page'
213
207
  visit pages.edit_page_path(_page)
214
- Page.count.should == 1
208
+ Page.count.should == 2
215
209
  click_link 'Delete'
216
- Page.count.should == 0
210
+ Page.count.should == 1
217
211
  page.should have_text 'removed successfully'
218
212
  end
219
213
  end
@@ -228,7 +222,7 @@ module ConstructorPages
228
222
  click_button 'Create Page'
229
223
  page.should have_content 'added successfully'
230
224
 
231
- _page = Page.first
225
+ _page = Page.last
232
226
  _page.short_description.should == ''
233
227
 
234
228
  visit pages.edit_page_path(_page)
@@ -240,37 +234,6 @@ module ConstructorPages
240
234
 
241
235
  _page.short_description.should == 'This is short description'
242
236
  end
243
-
244
- it 'should change fields if template change' do
245
- Field.create name: 'Price', code_name: 'price', template: @template, type_value: 'float'
246
- _template = Template.create name: 'Brand', code_name: 'brand'
247
- Field.create name: 'Amount', code_name: 'amount', template: _template, type_value: 'integer'
248
-
249
- visit pages.new_page_path
250
- fill_in 'Name', with: 'Simple page'
251
- click_button 'Create Page'
252
- _page = Page.first
253
- visit pages.edit_page_path(_page)
254
- page.should have_selector('#fields_price')
255
- fill_in 'Price', with: '250.20'
256
- click_button 'Update Page'
257
- _page.reload
258
- _page.price.should == 250.2
259
- visit pages.edit_page_path(_page)
260
- select 'Brand', from: 'Template'
261
- click_button 'Update Page'
262
- _page.reload
263
- _page.template.should == _template
264
- _page.price.should be_nil
265
- _page.amount.should == 0
266
- visit pages.edit_page_path(_page)
267
- page.should_not have_selector('#fields_price')
268
- page.should have_selector('#fields_amount')
269
- fill_in 'Amount', with: 200
270
- click_button 'Update Page'
271
- _page.reload
272
- _page.amount.should == 200
273
- end
274
237
  end
275
238
  end
276
239
  end
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  require 'spec_helper'
4
2
 
5
3
  module ConstructorPages
@@ -18,6 +16,9 @@ module ConstructorPages
18
16
  "constructor_pages/types/#{t}_type".classify.constantize.delete_all
19
17
  end
20
18
 
19
+ @template = Template.create name: 'Page', code_name: 'page'
20
+ @page = Page.create name: 'Page'
21
+
21
22
  login_as @user
22
23
  end
23
24
 
@@ -42,16 +43,14 @@ module ConstructorPages
42
43
  end
43
44
 
44
45
  it 'should has list of templates' do
45
- Template.create name: 'Page', code_name: 'page'
46
46
  visit pages.templates_path
47
47
  page.should have_selector 'ul li'
48
48
  page.should have_text 'Page'
49
49
  end
50
50
 
51
51
  it 'should has edit_template link' do
52
- _template = Template.create name: 'Page', code_name: 'page'
53
52
  visit pages.templates_path
54
- page.should have_link 'Page', pages.edit_template_path(_template)
53
+ page.should have_link 'Page', pages.edit_template_path(@template)
55
54
  end
56
55
  end
57
56
 
@@ -80,11 +79,6 @@ module ConstructorPages
80
79
  page.should have_field 'Code name'
81
80
  end
82
81
 
83
- it 'should has parent select' do
84
- visit pages.new_template_path
85
- page.should have_select 'Parent'
86
- end
87
-
88
82
  it 'should not has link new field' do
89
83
  visit pages.new_template_path
90
84
  page.should_not have_link 'New field'
@@ -104,11 +98,11 @@ module ConstructorPages
104
98
  visit pages.new_template_path
105
99
  fill_in 'Name', with: 'Brand'
106
100
  fill_in 'Code name', with: 'brand'
107
- Template.count.should == 0
101
+ Template.count.should == 1
108
102
  click_button 'Create Template'
109
103
  current_path.should == pages.templates_path
110
- Template.count.should == 1
111
- _template = Template.first
104
+ Template.count.should == 2
105
+ _template = Template.last
112
106
  _template.name.should == 'Brand'
113
107
  _template.code_name.should == 'brand'
114
108
  page.should have_text 'added successfully'
@@ -128,18 +122,14 @@ module ConstructorPages
128
122
  visit pages.new_template_path
129
123
  fill_in 'Name', with: 'Brand'
130
124
  fill_in 'Code name', with: 'get_field_value'
131
- Template.count.should == 0
125
+ Template.count.should == 1
132
126
  click_button 'Create Template'
133
- Template.count.should == 0
127
+ Template.count.should == 1
134
128
  page.should have_text 'Code name has already been taken'
135
129
  end
136
130
  end
137
131
 
138
132
  describe 'Edit template' do
139
- before :each do
140
- @template = Template.create name: 'Page', code_name: 'page'
141
- end
142
-
143
133
  describe 'Access' do
144
134
  it 'should be accessed by edit_template_path if logged in' do
145
135
  visit pages.edit_template_path(@template)
@@ -182,22 +172,19 @@ module ConstructorPages
182
172
 
183
173
  describe 'Delete template' do
184
174
  it 'should delete from template' do
185
- _template = Template.create name: 'Page', code_name: 'page'
186
- visit pages.edit_template_path(_template)
175
+ visit pages.edit_template_path(@template)
176
+ Page.destroy_all
187
177
  Template.count.should == 1
188
178
  click_link 'Delete'
189
179
  Template.count.should == 0
190
180
  page.should have_text 'removed successfully'
191
181
  end
192
182
 
193
- it 'should not delete if there are any pages' do
194
- _template = Template.create name: 'Page', code_name: 'page'
195
- Page.create name: 'Home page', template: _template
196
- visit pages.edit_template_path(_template)
197
- Template.count.should == 1
183
+ it 'should delete all pages with this template' do
184
+ page = Page.create name: 'Home page', template: @template
185
+ visit pages.edit_template_path(@template)
198
186
  click_link 'Delete'
199
- Template.count.should == 1
200
- page.should have_text 'Delete pages with this template before'
187
+ Page.where(id: page.id).any?.should be_false
201
188
  end
202
189
  end
203
190
  end
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  require 'spec_helper'
4
2
 
5
3
  module ConstructorPages
@@ -26,20 +26,19 @@ module ConstructorPages
26
26
  end
27
27
  end
28
28
 
29
- describe '.find_by_request_or_first' do
29
+ describe '.find_by_path' do
30
30
  before :each do
31
31
  @first_page = Page.create name: 'New page'
32
32
  @second_page = Page.create name: 'Second page'
33
33
  end
34
34
 
35
35
  it 'should return page by given request path' do
36
- Page.find_by_request_or_first('/new-page').should == @first_page
37
- Page.find_by_request_or_first('/second-page').should == @second_page
36
+ Page.find_by_path('/new-page').should == @first_page
37
+ Page.find_by_path('/second-page').should == @second_page
38
38
  end
39
39
 
40
- it 'should return first page if no given request or request is home page' do
41
- Page.find_by_request_or_first.should == @first_page
42
- Page.find_by_request_or_first('/').should == @first_page
40
+ it 'should return first page if request is home page' do
41
+ Page.find_by_path('/').should == @first_page
43
42
  end
44
43
  end
45
44
 
@@ -204,17 +203,6 @@ module ConstructorPages
204
203
  @page.price.should == 1000
205
204
  @page.amount.should == 20
206
205
  end
207
-
208
- it 'should reset boolean fields' do
209
- Field.create name: 'Check', code_name: 'check', template: @template, type_value: 'boolean'
210
-
211
- @page.check = true
212
-
213
- @page.update_fields_values({price: 1000})
214
-
215
- @page.price.should == 1000
216
- @page.check.should be_false
217
- end
218
206
  end
219
207
 
220
208
  describe '#remove_fields_values' do
@@ -291,19 +279,6 @@ module ConstructorPages
291
279
  page.redirect?.should be_true
292
280
  end
293
281
  end
294
-
295
- describe '#touch_branch' do
296
- it 'should touch all pages in same branch' do
297
- page = Page.create name: 'Hello world'
298
- second_page = Page.create name: 'Again', parent: page
299
- page.reload
300
-
301
- updated = second_page.updated_at
302
- page.touch_branch
303
- second_page.reload
304
- second_page.updated_at.should_not == updated
305
- end
306
- end
307
282
  end
308
283
 
309
284
  context 'ATTRIBUTES' do
@@ -320,7 +295,7 @@ module ConstructorPages
320
295
  Template.delete_all
321
296
 
322
297
  page = Page.create
323
- page.valid?.should_not be_true
298
+ page.valid?.should be_false
324
299
  end
325
300
  end
326
301
 
@@ -330,6 +305,15 @@ module ConstructorPages
330
305
  page.template.should == Template.first
331
306
  end
332
307
  end
308
+
309
+ context 'if template changed' do
310
+ it 'should not be valid' do
311
+ another_template = Template.create name: 'Another template', code_name: 'another_template'
312
+ page = Page.create template: @template
313
+ page.template = another_template
314
+ page.valid?.should be_false
315
+ end
316
+ end
333
317
  end
334
318
 
335
319
  describe '#url' do