constructor-cms 0.6.4 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +7 -3
  3. data/Gemfile +9 -0
  4. data/README.md +2 -2
  5. data/constructor-cms.gemspec +0 -1
  6. data/core/config/initializers/devise.rb +8 -8
  7. data/core/config/locales/devise.en.yml +37 -37
  8. data/core/config/locales/devise.fr.yml +74 -0
  9. data/core/config/locales/devise.ru.yml +40 -40
  10. data/core/config/locales/en.yml +14 -14
  11. data/core/config/locales/fr.yml +15 -0
  12. data/core/config/locales/ru.yml +20 -20
  13. data/core/lib/constructor_core/version.rb +1 -1
  14. data/pages/app/controllers/constructor_pages/fields_controller.rb +7 -11
  15. data/pages/app/models/constructor_pages/page.rb +70 -40
  16. data/pages/app/views/constructor_pages/fields/_form.haml +2 -1
  17. data/pages/config/locales/en.yml +57 -54
  18. data/pages/config/locales/fr.yml +65 -0
  19. data/pages/config/locales/ru.yml +48 -44
  20. data/pages/spec/features/constructor_pages/fields_controller_spec.rb +217 -0
  21. data/pages/spec/features/constructor_pages/pages_controller_spec.rb +4 -1
  22. data/pages/spec/features/constructor_pages/templates_controller_spec.rb +4 -0
  23. data/pages/spec/helpers/constructor_pages/.keep +0 -0
  24. data/pages/spec/models/constructor_pages/page_model_spec.rb +97 -0
  25. data/pages/spec/models/constructor_pages/template_model_spec.rb +5 -0
  26. data/pages/spec/models/constructor_pages/types/boolean_type_model_spec.rb +21 -0
  27. data/pages/spec/models/constructor_pages/types/date_type_model_spec.rb +21 -0
  28. data/pages/spec/models/constructor_pages/types/float_type_model_spec.rb +21 -0
  29. data/pages/spec/models/constructor_pages/types/html_type_model_spec.rb +63 -0
  30. data/pages/spec/models/constructor_pages/types/integer_type_model_spec.rb +24 -0
  31. data/pages/spec/models/constructor_pages/types/string_type_model_spec.rb +21 -0
  32. data/pages/spec/models/constructor_pages/types/text_type_model_spec.rb +63 -0
  33. data/pages/spec/routing/constructor_pages/.keep +0 -0
  34. data/spec/spec_helper.rb +2 -0
  35. metadata +19 -20
@@ -0,0 +1,217 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ module ConstructorPages
6
+ describe 'Fields Controller' do
7
+ before :all do
8
+ ConstructorCore::User.delete_all
9
+ @user = ConstructorCore::User.create email: 'ivanzotov@gmail.com', password: '123qweASD'
10
+ end
11
+
12
+ before :each do
13
+ Page.delete_all
14
+ Field.delete_all
15
+ Template.delete_all
16
+
17
+ Field::TYPES.each do |t|
18
+ "constructor_pages/types/#{t}_type".classify.constantize.delete_all
19
+ end
20
+
21
+ @template = Template.create name: 'Page', code_name: 'page'
22
+
23
+ login_as @user
24
+ end
25
+
26
+ describe 'Index' do
27
+ before :each do
28
+ @template = Template.create name: 'Brand', code_name: 'brand'
29
+ @content_field = Field.create name: 'Content', code_name: 'content', template: @template, type_value: 'text'
30
+ @price_field = Field.create name: 'Price', code_name: 'price', template: @template, type_value: 'float'
31
+ end
32
+
33
+ it 'should list all fields of template' do
34
+ visit pages.edit_template_path(@template)
35
+ page.should have_text 'Content'
36
+ page.should have_text 'Price'
37
+ end
38
+
39
+ it 'should has edit field link' do
40
+ visit pages.edit_template_path(@template)
41
+ find("a[href='#{pages.edit_field_path(@content_field, @template)}']").should be_true
42
+ find("a[href='#{pages.edit_field_path(@price_field, @template)}']").should be_true
43
+ end
44
+
45
+ it 'should has delete field link' do
46
+ visit pages.edit_template_path(@template)
47
+ find("a[href='#{pages.field_path(@content_field)}']").should be_true
48
+ find("a[href='#{pages.field_path(@price_field)}']").should be_true
49
+ end
50
+
51
+ it 'should has move field link' do
52
+ visit pages.edit_template_path(@template)
53
+ find("a[href='#{pages.field_move_down_path(@content_field)}']").should be_true
54
+ find("a[href='#{pages.field_move_up_path(@price_field)}']").should be_true
55
+ end
56
+ end
57
+
58
+ describe 'New field' do
59
+ before :each do
60
+ @template = Template.create name: 'Brand', code_name: 'brand'
61
+ end
62
+
63
+ context 'Access' do
64
+ it 'should be accessed by new_field_path if loggen in' do
65
+ visit pages.new_field_path(@template)
66
+ current_path.should == pages.new_field_path(@template)
67
+ status_code.should == 200
68
+ end
69
+
70
+ it 'should not be accessed by new_field_path if not loggen in' do
71
+ logout
72
+ visit pages.new_field_path(@template)
73
+ current_path.should == '/'
74
+ end
75
+ end
76
+
77
+ context 'Contain' do
78
+ before :each do
79
+ @content_field = Field.create name: 'Content', code_name: 'content', template: @template, type_value: 'text'
80
+ @price_field = Field.create name: 'Price', code_name: 'price', template: @template, type_value: 'float'
81
+ end
82
+
83
+ it 'should has name field' do
84
+ visit pages.new_field_path(@template)
85
+ page.should have_field 'Name'
86
+ end
87
+
88
+ it 'should has code name field' do
89
+ visit pages.new_field_path(@template)
90
+ page.should have_field 'Code name'
91
+ end
92
+
93
+ it 'should has select type' do
94
+ visit pages.new_field_path(@template)
95
+ page.should have_select 'Type value'
96
+ end
97
+
98
+ it 'should has no delete link' do
99
+ visit pages.new_field_path(@template)
100
+ page.should_not have_link 'Delete'
101
+ end
102
+
103
+ it 'should has Create Field button' do
104
+ visit pages.new_field_path(@template)
105
+ page.should have_button 'Create Field'
106
+ end
107
+ end
108
+
109
+ it 'should create new field' do
110
+ visit pages.new_field_path(@template)
111
+ fill_in 'Name', with: 'Amount'
112
+ fill_in 'Code name', with: 'amount'
113
+ select 'Integer', from: 'Type value'
114
+ Field.count.should == 0
115
+ click_button 'Create Field'
116
+ Field.count.should == 1
117
+ _field = Field.first
118
+ _field.name.should == 'Amount'
119
+ _field.code_name.should == 'amount'
120
+ _field.type_value.should == 'integer'
121
+ current_path.should == pages.edit_template_path(@template)
122
+ page.should have_text 'added successfully'
123
+ page.should have_text 'Amount'
124
+ end
125
+
126
+ it 'should validate uniqueness of code_name' do
127
+ visit pages.new_field_path(@template)
128
+ fill_in 'Name', with: 'Hello'
129
+ fill_in 'Code name', with: 'get_field_value'
130
+ Field.count.should == 0
131
+ click_button 'Create Field'
132
+ Field.count.should == 0
133
+ current_path.should == pages.fields_path
134
+ page.should have_text 'Code name has already been taken'
135
+
136
+ visit pages.new_field_path(@template)
137
+ fill_in 'Name', with: 'Hello'
138
+ fill_in 'Code name', with: 'brand'
139
+ Field.count.should == 0
140
+ click_button 'Create Field'
141
+ Field.count.should == 0
142
+ current_path.should == pages.fields_path
143
+ page.should have_text 'Code name has already been taken'
144
+ end
145
+ end
146
+
147
+ describe 'Edit field' do
148
+ before :each do
149
+ @template = Template.create name: 'Brand', code_name: 'brand'
150
+ @field_content = Field.create name: 'Content', code_name: 'content', template: @template, type_value: 'text'
151
+ end
152
+
153
+ context 'Access' do
154
+ it 'should be accessed by edit_field_path if loggen in' do
155
+ visit pages.edit_field_path(@field_content, @template)
156
+ current_path.should == pages.edit_field_path(@field_content, @template)
157
+ status_code.should == 200
158
+ end
159
+
160
+ it 'should not be accessed by new_field_path if not loggen in' do
161
+ logout
162
+ visit pages.edit_field_path(@field_content, @template)
163
+ current_path.should == '/'
164
+ end
165
+ end
166
+
167
+ it 'should has delete link' do
168
+ visit pages.edit_field_path(@field_content, @template)
169
+ page.should have_link 'Delete', pages.field_path(@field_content)
170
+ end
171
+
172
+ it 'should has Update Field button' do
173
+ visit pages.edit_field_path(@field_content, @template)
174
+ page.should have_button 'Update Field'
175
+ end
176
+
177
+ it 'should edit field' do
178
+ visit pages.edit_field_path(@field_content, @template)
179
+ fill_in 'Name', with: 'Long content'
180
+ fill_in 'Code name', with: 'long_content'
181
+ select 'HTML', from: 'Type value'
182
+ click_button 'Update Field'
183
+ @field_content.reload
184
+ @field_content.name.should == 'Long content'
185
+ @field_content.code_name.should == 'long_content'
186
+ @field_content.type_value.should == 'html'
187
+ current_path.should == pages.edit_template_path(@template)
188
+ page.should have_text 'updated successfully'
189
+ end
190
+ end
191
+
192
+ describe 'Delete field' do
193
+ before :each do
194
+ @template = Template.create name: 'Brand', code_name: 'brand'
195
+ @field_content = Field.create name: 'Content', code_name: 'content', template: @template, type_value: 'text'
196
+ end
197
+
198
+ it 'should delete field from template edit' do
199
+ visit pages.edit_template_path(@template)
200
+ Field.count.should == 1
201
+ find("a[href='#{pages.field_path(@field_content)}']").click
202
+ Field.count.should == 0
203
+ current_path.should == pages.edit_template_path(@template)
204
+ page.should have_text 'removed successfully'
205
+ end
206
+
207
+ it 'should delete from field edit' do
208
+ visit pages.edit_field_path(@field_content, @template)
209
+ Field.count.should == 1
210
+ click_link 'Delete'
211
+ Field.count.should == 0
212
+ current_path.should == pages.edit_template_path(@template)
213
+ page.should have_text 'removed successfully'
214
+ end
215
+ end
216
+ end
217
+ end
@@ -183,6 +183,7 @@ module ConstructorPages
183
183
  _page.name.should == 'Hello world'
184
184
  _page.url.should == 'hello-world'
185
185
  current_path.should == pages.pages_path
186
+ page.should have_text 'added successfully'
186
187
  end
187
188
 
188
189
  it 'should redirect to back if no template exists' do
@@ -230,6 +231,7 @@ module ConstructorPages
230
231
  @page.title.should == 'Zanussi conditioners'
231
232
  @page.keywords.should == 'Zanussi, conditioners, Voronezh'
232
233
  @page.description.should == 'Zanussi conditioners Voronezh'
234
+ page.should have_text 'updated successfully'
233
235
  end
234
236
  end
235
237
 
@@ -240,6 +242,7 @@ module ConstructorPages
240
242
  Page.count.should == 1
241
243
  click_link 'Delete'
242
244
  Page.count.should == 0
245
+ page.should have_text 'removed successfully'
243
246
  end
244
247
 
245
248
  it 'should delete from page' do
@@ -248,6 +251,7 @@ module ConstructorPages
248
251
  Page.count.should == 1
249
252
  click_link 'Delete'
250
253
  Page.count.should == 0
254
+ page.should have_text 'removed successfully'
251
255
  end
252
256
  end
253
257
 
@@ -271,7 +275,6 @@ module ConstructorPages
271
275
 
272
276
  click_button 'Update Page'
273
277
 
274
- _page.reload
275
278
  _page.short_description.should == 'This is short description'
276
279
  end
277
280
 
@@ -165,6 +165,7 @@ module ConstructorPages
165
165
  _template = Template.first
166
166
  _template.name.should == 'Brand'
167
167
  _template.code_name.should == 'brand'
168
+ page.should have_text 'added successfully'
168
169
  end
169
170
 
170
171
  it 'should validate uniqueness of code name' do
@@ -229,6 +230,7 @@ module ConstructorPages
229
230
  @template.reload
230
231
  @template.name.should == 'New brand'
231
232
  @template.code_name.should == 'new_brand'
233
+ page.should have_text 'updated successfully'
232
234
  end
233
235
  end
234
236
 
@@ -239,6 +241,7 @@ module ConstructorPages
239
241
  Template.count.should == 1
240
242
  click_link 'Delete'
241
243
  Template.count.should == 0
244
+ page.should have_text 'removed successfully'
242
245
  end
243
246
 
244
247
  it 'should delete from template' do
@@ -247,6 +250,7 @@ module ConstructorPages
247
250
  Template.count.should == 1
248
251
  click_link 'Delete'
249
252
  Template.count.should == 0
253
+ page.should have_text 'removed successfully'
250
254
  end
251
255
 
252
256
  it 'should not delete if there are any pages' do
File without changes
@@ -59,6 +59,103 @@ module ConstructorPages
59
59
  end
60
60
  end
61
61
 
62
+ describe 'SEARCH' do
63
+ before :each do
64
+ @price_field = Field.create name: 'Price', code_name: 'price', template: @template, type_value: 'float'
65
+ @area_field = Field.create name: 'Area', code_name: 'area', template: @template, type_value: 'integer'
66
+
67
+ @brand_template = Template.create name: 'Brand', code_name: 'brand', parent: @template
68
+ @content_field = Field.create name: 'Content', code_name: 'content', template: @brand_template, type_value: 'text'
69
+ @check_field = Field.create name: 'Check', code_name: 'check', template: @brand_template, type_value: 'boolean'
70
+ @brand_price_field = Field.create name: 'Price', code_name: 'price', template: @brand_template, type_value: 'float'
71
+ @brand_area_field = Field.create name: 'Area', code_name: 'area', template: @brand_template, type_value: 'integer'
72
+
73
+ @page = Page.create name: 'Fresco', template: @template
74
+ @page.price = 15000
75
+ @page.area = 35
76
+
77
+ @second_page = Page.create name: 'Zanussi', template: @template
78
+ @second_page.price = 1000
79
+ @second_page.area = 10
80
+
81
+ @first_brand_page = Page.create name: 'Midea', template: @brand_template, parent: @page
82
+ @first_brand_page.price = 20000
83
+ @first_brand_page.area = 25
84
+ @first_brand_page.content = 'This is first brand page'
85
+ @first_brand_page.check = true
86
+
87
+ @second_brand_page = Page.create name: 'Dantex', template: @brand_template, parent: @page
88
+ @second_brand_page.price = 30000
89
+ @second_brand_page.area = 55
90
+ @second_brand_page.content = 'This is second brand page'
91
+ @second_brand_page.check = false
92
+
93
+ @third_brand_page = Page.create name: 'LG', template: @brand_template, parent: @second_page
94
+ @third_brand_page.price = 10000
95
+ @third_brand_page.area = 38
96
+ @third_brand_page.content = 'This is third brand page'
97
+ @third_brand_page.check = true
98
+
99
+ @page.reload
100
+ @second_page.reload
101
+ end
102
+
103
+ context 'search in all pages' do
104
+ it 'should search with what search' do
105
+ Page.search.should == [@page, @first_brand_page, @second_brand_page, @second_page, @third_brand_page]
106
+ Page.search(:hello).should == []
107
+ Page.search(:brand).should == [@first_brand_page, @second_brand_page, @third_brand_page]
108
+ Page.search(:brands).should == [@first_brand_page, @second_brand_page, @third_brand_page]
109
+ end
110
+
111
+ it 'should search with where string search' do
112
+ Page.search_in('/world').should == []
113
+ end
114
+
115
+ it 'should search with where page search' do
116
+ Page.search_in(@page).should == [@first_brand_page, @second_brand_page]
117
+ Page.in(@second_page).search(:brands).should == [@third_brand_page]
118
+ Page.in(@second_page).search(:brand).should == [@third_brand_page]
119
+ Page.in(@second_page).search('brand').should == [@third_brand_page]
120
+ end
121
+
122
+ it 'it should search with by params' do
123
+ Page.in(@page).search_by(area: 25).should == [@first_brand_page]
124
+ Page.search_by(area: 10).should == [@second_page]
125
+ Page.search_by(price: 15000).should == [@page]
126
+ Page.in(@page).by(area: 25).search(:brand).should == [@first_brand_page]
127
+ Page.in(@second_page).by(area: 38).search(:brand).should == [@third_brand_page]
128
+ Page.in(@second_page).by(area: 40).search(:brand).should == []
129
+ Page.in('/world').search_by(area: 10).should == []
130
+ end
131
+
132
+ it 'should search with less' do
133
+ pending#Page.search(price: ['<', 20000]).should == [@page]
134
+ end
135
+
136
+ it 'should search with more' do
137
+ pending#Page.search(price: ['<', 20000], price: ['>', 5000]).should == [@page, @second_page]
138
+ end
139
+ end
140
+
141
+
142
+ context 'search in certain page' do
143
+ it 'should search with what search' do
144
+ @page.search.should == [@first_brand_page, @second_brand_page]
145
+ @page.search(:hello).should == []
146
+ @page.search(:brand).should == [@first_brand_page, @second_brand_page]
147
+ @second_page.search(:brand).should == [@third_brand_page]
148
+ end
149
+
150
+ it 'it should search with by params' do
151
+ @page.search_by(area: 25).should == [@first_brand_page]
152
+ @page.search_by(price: 30000).should == [@second_brand_page]
153
+ @page.search_by(area: 10).should == []
154
+ end
155
+ end
156
+ end
157
+
158
+
62
159
  context 'INSTANCE METHODS' do
63
160
  context 'Getting and setting field value' do
64
161
  before :each do
@@ -13,6 +13,11 @@ module ConstructorPages
13
13
  _template.valid?.should be_true
14
14
  end
15
15
 
16
+ it 'should be uniqueness with Page' do
17
+ _template = Template.create name: 'Page', code_name: 'get_field_value'
18
+ _template.valid?.should be_false
19
+ end
20
+
16
21
  describe '#child' do
17
22
  it 'should return child corresponding child_id or children first' do
18
23
  _brand = Template.create name: 'Brand', code_name: 'brand'
@@ -0,0 +1,21 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ module ConstructorPages
6
+ module Types
7
+ describe 'Boolean type' do
8
+ it 'should contain boolean type values' do
9
+ Template.delete_all
10
+ _template = Template.create name: 'Product', code_name: 'product'
11
+ _field = Field.create name: 'Available', code_name: 'available', template: _template, type_value: 'boolean'
12
+ _page = Page.create name: 'TV', template: _template
13
+ _boolean = BooleanType.create value: true, field: _field, page: _page
14
+ _boolean.value.should == true
15
+ _boolean.update value: 0
16
+ _boolean.reload
17
+ _boolean.value.should == false
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ module ConstructorPages
6
+ module Types
7
+ describe 'Date type' do
8
+ it 'should contain date type values' do
9
+ Template.delete_all
10
+ _template = Template.create name: 'Product', code_name: 'product'
11
+ _field = Field.create name: 'Update date', code_name: 'update_date', template: _template, type_value: 'date'
12
+ _page = Page.create name: 'TV', template: _template
13
+ _date = DateType.create value: Time.now, field: _field, page: _page
14
+ _date.value.should == Date.today
15
+ _date.update value: '2013-05-07'
16
+ _date.reload
17
+ _date.value.should == Date.parse('2013-05-07')
18
+ end
19
+ end
20
+ end
21
+ end