alchemy_cms 3.0.4 → 3.1.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (210) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +4 -6
  3. data/Gemfile +4 -7
  4. data/README.md +207 -115
  5. data/alchemy_cms.gemspec +10 -9
  6. data/app/assets/javascripts/alchemy/alchemy.dragndrop.js.coffee +2 -2
  7. data/app/assets/javascripts/alchemy/alchemy.image_cropper.js.coffee +2 -2
  8. data/app/assets/javascripts/alchemy/alchemy.js +6 -7
  9. data/app/assets/javascripts/alchemy/alchemy.translations.js.coffee +1 -43
  10. data/app/assets/javascripts/alchemy/alchemy.uploader.js.coffee +1 -1
  11. data/app/assets/stylesheets/alchemy/_mixins.scss +2 -1
  12. data/app/assets/stylesheets/alchemy/buttons.scss +0 -5
  13. data/app/assets/stylesheets/alchemy/dialogs.scss +1 -0
  14. data/app/assets/stylesheets/alchemy/frame.scss +9 -12
  15. data/app/assets/stylesheets/tinymce/skins/alchemy/content.min.css.scss +11 -2
  16. data/app/assets/stylesheets/tinymce/skins/alchemy/skin.min.css.scss +9 -1
  17. data/app/controllers/alchemy/admin/attachments_controller.rb +2 -4
  18. data/app/controllers/alchemy/admin/essence_pictures_controller.rb +34 -38
  19. data/app/controllers/alchemy/api/base_controller.rb +19 -0
  20. data/app/controllers/alchemy/api/contents_controller.rb +35 -0
  21. data/app/controllers/alchemy/api/elements_controller.rb +29 -0
  22. data/app/controllers/alchemy/api/pages_controller.rb +32 -0
  23. data/app/controllers/alchemy/contents_controller.rb +1 -0
  24. data/app/controllers/alchemy/elements_controller.rb +5 -2
  25. data/app/controllers/alchemy/pages_controller.rb +4 -1
  26. data/app/controllers/alchemy/pictures_controller.rb +4 -36
  27. data/app/helpers/alchemy/admin/essences_helper.rb +5 -2
  28. data/app/helpers/alchemy/essences_helper.rb +14 -1
  29. data/app/models/alchemy/content.rb +32 -4
  30. data/app/models/alchemy/element.rb +2 -16
  31. data/app/models/alchemy/element/presenters.rb +2 -2
  32. data/app/models/alchemy/essence_file.rb +5 -0
  33. data/app/models/alchemy/essence_picture.rb +12 -8
  34. data/app/models/alchemy/picture.rb +1 -74
  35. data/app/models/alchemy/picture/transformations.rb +249 -0
  36. data/app/serializers/alchemy/content_serializer.rb +3 -10
  37. data/app/serializers/alchemy/element_serializer.rb +6 -3
  38. data/app/serializers/alchemy/legacy_element_serializer.rb +17 -0
  39. data/app/views/alchemy/admin/dashboard/_sites.html.erb +14 -4
  40. data/app/views/alchemy/admin/essence_pictures/crop.html.erb +8 -5
  41. data/app/views/alchemy/admin/pages/edit.html.erb +9 -9
  42. data/app/views/alchemy/admin/pictures/info.html.erb +2 -3
  43. data/app/views/alchemy/admin/tags/edit.html.erb +1 -1
  44. data/app/views/alchemy/essences/_essence_boolean_editor.html.erb +8 -7
  45. data/app/views/alchemy/essences/_essence_boolean_view.html.erb +3 -3
  46. data/app/views/alchemy/essences/_essence_date_editor.html.erb +8 -2
  47. data/app/views/alchemy/essences/_essence_date_view.html.erb +10 -8
  48. data/app/views/alchemy/essences/_essence_file_editor.html.erb +48 -53
  49. data/app/views/alchemy/essences/_essence_file_view.html.erb +5 -5
  50. data/app/views/alchemy/essences/_essence_html_editor.html.erb +5 -4
  51. data/app/views/alchemy/essences/_essence_link_editor.html.erb +17 -15
  52. data/app/views/alchemy/essences/_essence_link_view.html.erb +11 -7
  53. data/app/views/alchemy/essences/_essence_picture_editor.html.erb +4 -2
  54. data/app/views/alchemy/essences/_essence_picture_view.html.erb +4 -2
  55. data/app/views/alchemy/essences/_essence_richtext_view.html.erb +5 -4
  56. data/app/views/alchemy/essences/_essence_select_editor.html.erb +22 -32
  57. data/app/views/alchemy/essences/_essence_text_view.html.erb +7 -6
  58. data/app/views/alchemy/essences/shared/_essence_picture_tools.html.erb +1 -1
  59. data/app/views/layouts/alchemy/admin.html.erb +5 -3
  60. data/config/initializers/inflections.rb +3 -0
  61. data/config/initializers/simple_form.rb +1 -1
  62. data/config/locales/alchemy.en.yml +0 -1
  63. data/config/routes.rb +14 -0
  64. data/lib/alchemy/capistrano.rb +71 -0
  65. data/lib/alchemy/engine.rb +0 -3
  66. data/lib/alchemy/essence.rb +1 -1
  67. data/lib/alchemy/permissions.rb +19 -5
  68. data/lib/alchemy/picture_attributes.rb +1 -1
  69. data/lib/alchemy/test_support/auth_helpers.rb +1 -1
  70. data/lib/alchemy/test_support/essence_shared_examples.rb +37 -22
  71. data/lib/alchemy/test_support/integration_helpers.rb +1 -1
  72. data/lib/alchemy/tinymce.rb +21 -4
  73. data/lib/alchemy/upgrader/three_point_one.rb +43 -0
  74. data/lib/alchemy/upgrader/three_point_zero.rb +13 -0
  75. data/lib/alchemy/version.rb +2 -1
  76. data/lib/rails/generators/alchemy/module/module_generator.rb +30 -0
  77. data/lib/rails/generators/alchemy/module/templates/ability.rb.tt +11 -0
  78. data/lib/rails/generators/alchemy/module/templates/controller.rb.tt +2 -0
  79. data/lib/rails/generators/alchemy/module/templates/module_config.rb.tt +15 -0
  80. data/lib/rails/generators/alchemy/scaffold/scaffold_generator.rb +0 -1
  81. data/lib/rails/templates/alchemy.rb +2 -2
  82. data/lib/tasks/alchemy/db.rake +7 -1
  83. data/spec/controllers/admin/attachments_controller_spec.rb +38 -38
  84. data/spec/controllers/admin/base_controller_spec.rb +18 -18
  85. data/spec/controllers/admin/clipboard_controller_spec.rb +23 -18
  86. data/spec/controllers/admin/contents_controller_spec.rb +33 -27
  87. data/spec/controllers/admin/dashboard_controller_spec.rb +14 -14
  88. data/spec/controllers/admin/elements_controller_spec.rb +125 -105
  89. data/spec/controllers/admin/essence_files_controller_spec.rb +6 -7
  90. data/spec/controllers/admin/essence_pictures_controller_spec.rb +52 -42
  91. data/spec/controllers/admin/languages_controller_spec.rb +3 -3
  92. data/spec/controllers/admin/pages_controller_spec.rb +81 -71
  93. data/spec/controllers/admin/pictures_controller_spec.rb +69 -72
  94. data/spec/controllers/admin/resources_controller_spec.rb +5 -5
  95. data/spec/controllers/admin/trash_controller_spec.rb +15 -12
  96. data/spec/controllers/alchemy/admin/tags_controller_spec.rb +8 -8
  97. data/spec/controllers/alchemy/api/contents_controller_spec.rb +73 -0
  98. data/spec/controllers/alchemy/api/elements_controller_spec.rb +69 -0
  99. data/spec/controllers/alchemy/api/pages_controller_spec.rb +86 -0
  100. data/spec/controllers/attachments_controller_spec.rb +8 -8
  101. data/spec/controllers/contents_controller_spec.rb +22 -0
  102. data/spec/controllers/elements_controller_spec.rb +10 -4
  103. data/spec/controllers/messages_controller_spec.rb +35 -34
  104. data/spec/controllers/pages_controller_spec.rb +37 -28
  105. data/spec/controllers/pictures_controller_spec.rb +90 -23
  106. data/spec/dummy/app/models/dummy_user.rb +0 -4
  107. data/spec/dummy/app/views/alchemy/elements/_all_you_can_eat_editor.html.erb +11 -0
  108. data/spec/dummy/config/alchemy/elements.yml +22 -1
  109. data/spec/dummy/config/alchemy/page_layouts.yml +4 -0
  110. data/spec/dummy/config/application.rb +2 -1
  111. data/spec/dummy/config/environments/test.rb +3 -1
  112. data/spec/features/admin/dashboard_spec.rb +41 -6
  113. data/spec/features/admin/language_tree_feature_spec.rb +3 -3
  114. data/spec/features/admin/legacy_page_url_management_spec.rb +1 -1
  115. data/spec/features/admin/link_overlay_spec.rb +7 -7
  116. data/spec/features/admin/locale_select_feature_spec.rb +5 -2
  117. data/spec/features/admin/modules_integration_spec.rb +1 -1
  118. data/spec/features/admin/page_creation_feature_spec.rb +3 -2
  119. data/spec/features/admin/page_editing_feature_spec.rb +66 -79
  120. data/spec/features/admin/picture_library_integration_spec.rb +8 -8
  121. data/spec/features/admin/resources_integration_spec.rb +21 -21
  122. data/spec/features/admin/tinymce_feature_spec.rb +36 -0
  123. data/spec/features/navigation_spec.rb +1 -1
  124. data/spec/features/page_feature_spec.rb +34 -34
  125. data/spec/features/picture_security_spec.rb +4 -4
  126. data/spec/features/security_spec.rb +1 -1
  127. data/spec/features/translation_integration_spec.rb +7 -7
  128. data/spec/helpers/admin/base_helper_spec.rb +51 -49
  129. data/spec/helpers/admin/contents_helper_spec.rb +11 -11
  130. data/spec/helpers/admin/elements_helper_spec.rb +20 -17
  131. data/spec/helpers/admin/essences_helper_spec.rb +42 -11
  132. data/spec/helpers/admin/navigation_helper_spec.rb +64 -54
  133. data/spec/helpers/admin/pages_helper_spec.rb +10 -10
  134. data/spec/helpers/admin/tags_helper_spec.rb +16 -16
  135. data/spec/helpers/base_helper_spec.rb +11 -11
  136. data/spec/helpers/elements_block_helper_spec.rb +24 -24
  137. data/spec/helpers/elements_helper_spec.rb +46 -46
  138. data/spec/helpers/essences_helper_spec.rb +90 -17
  139. data/spec/helpers/pages_helper_spec.rb +53 -53
  140. data/spec/helpers/picture_url_helpers_spec.rb +6 -6
  141. data/spec/helpers/url_helper_spec.rb +32 -32
  142. data/spec/libraries/config_spec.rb +9 -9
  143. data/spec/libraries/controller_actions_spec.rb +14 -14
  144. data/spec/libraries/i18n_spec.rb +6 -6
  145. data/spec/libraries/kaminari/scoped_pagination_url_helper_spec.rb +4 -4
  146. data/spec/libraries/modules_spec.rb +4 -4
  147. data/spec/libraries/mount_point_spec.rb +13 -13
  148. data/spec/libraries/page_layout_spec.rb +24 -24
  149. data/spec/libraries/permissions_spec.rb +97 -80
  150. data/spec/libraries/resource_spec.rb +37 -37
  151. data/spec/libraries/resources_helper_spec.rb +19 -19
  152. data/spec/libraries/shell_spec.rb +17 -17
  153. data/spec/libraries/template_tracker_spec.rb +14 -14
  154. data/spec/libraries/tinymce_spec.rb +8 -8
  155. data/spec/libraries/userstamp_spec.rb +2 -2
  156. data/spec/mailers/messages_spec.rb +4 -4
  157. data/spec/models/attachment_spec.rb +86 -30
  158. data/spec/models/cell_spec.rb +10 -10
  159. data/spec/models/content_spec.rb +106 -46
  160. data/spec/models/element_spec.rb +94 -115
  161. data/spec/models/essence_date_spec.rb +1 -1
  162. data/spec/models/essence_file_spec.rb +4 -4
  163. data/spec/models/essence_picture_spec.rb +56 -25
  164. data/spec/models/essence_richtext_spec.rb +1 -1
  165. data/spec/models/essence_text_spec.rb +7 -7
  166. data/spec/models/language_spec.rb +12 -12
  167. data/spec/models/legacy_page_url_spec.rb +2 -2
  168. data/spec/models/message_spec.rb +12 -5
  169. data/spec/models/page_spec.rb +259 -235
  170. data/spec/models/picture_spec.rb +72 -166
  171. data/spec/models/site_spec.rb +41 -41
  172. data/spec/models/tag_spec.rb +7 -7
  173. data/spec/routing/api_routing_spec.rb +150 -0
  174. data/spec/routing/routing_spec.rb +28 -28
  175. data/spec/spec_helper.rb +6 -5
  176. data/spec/support/hint_examples.rb +5 -5
  177. data/spec/support/transformation_examples.rb +173 -0
  178. data/spec/tasks/helpers_spec.rb +29 -29
  179. data/spec/views/essences/essence_boolean_editor_spec.rb +32 -0
  180. data/spec/views/essences/essence_boolean_view_spec.rb +2 -2
  181. data/spec/views/essences/essence_date_view_spec.rb +1 -1
  182. data/spec/views/essences/essence_link_view_spec.rb +11 -0
  183. data/spec/views/essences/essence_picture_view_spec.rb +56 -11
  184. data/spec/views/essences/essence_richtext_view_spec.rb +12 -0
  185. data/spec/views/essences/essence_text_view_spec.rb +12 -0
  186. data/vendor/assets/javascripts/tinymce/langs/de.js +20 -2
  187. data/vendor/assets/javascripts/tinymce/langs/fr.js +14 -1
  188. data/vendor/assets/javascripts/tinymce/langs/nl.js +22 -4
  189. data/vendor/assets/javascripts/tinymce/plugins/anchor/plugin.min.js +1 -1
  190. data/vendor/assets/javascripts/tinymce/plugins/autoresize/plugin.min.js +1 -1
  191. data/vendor/assets/javascripts/tinymce/plugins/charmap/plugin.min.js +1 -1
  192. data/vendor/assets/javascripts/tinymce/plugins/code/plugin.min.js +1 -1
  193. data/vendor/assets/javascripts/tinymce/plugins/directionality/plugin.min.js +1 -1
  194. data/vendor/assets/javascripts/tinymce/plugins/fullscreen/plugin.min.js +1 -1
  195. data/vendor/assets/javascripts/tinymce/plugins/hr/plugin.min.js +1 -1
  196. data/vendor/assets/javascripts/tinymce/plugins/link/plugin.min.js +1 -1
  197. data/vendor/assets/javascripts/tinymce/plugins/paste/plugin.min.js +1 -1
  198. data/vendor/assets/javascripts/tinymce/plugins/tabfocus/plugin.min.js +1 -1
  199. data/vendor/assets/javascripts/tinymce/plugins/table/plugin.min.js +1 -1
  200. data/vendor/assets/javascripts/tinymce/themes/modern/theme.min.js +1 -1
  201. data/vendor/assets/javascripts/tinymce/tinymce.min.js +11 -10
  202. metadata +72 -42
  203. data/app/views/alchemy/messages/contact_form_mail.es.text.erb +0 -12
  204. data/config/locales/alchemy.es.yml +0 -958
  205. data/config/locales/alchemy.ru.yml +0 -837
  206. data/config/locales/simple_form.es.yml +0 -6
  207. data/config/locales/simple_form.ru.yml +0 -25
  208. data/lib/rails/generators/alchemy/scaffold/files/alchemy.es.yml +0 -31
  209. data/vendor/assets/javascripts/tinymce/langs/es.js +0 -197
  210. data/vendor/assets/javascripts/tinymce/langs/ru.js +0 -197
@@ -8,8 +8,8 @@ module Alchemy
8
8
 
9
9
  describe '#index' do
10
10
  before do
11
- Page.stub_chain(:from_current_site, :all_last_edited_from).and_return([])
12
- Page.stub_chain(:from_current_site, :all_locked).and_return([])
11
+ expect(Page).to receive(:from_current_site).and_return(double(all_last_edited_from: []))
12
+ expect(Page).to receive(:from_current_site).and_return(double(all_locked: []))
13
13
  end
14
14
 
15
15
  it "assigns @last_edited_pages" do
@@ -27,7 +27,7 @@ module Alchemy
27
27
  let(:another_user) { mock_model('DummyUser') }
28
28
 
29
29
  before do
30
- Alchemy.user_class.should_receive(:logged_in).and_return([another_user])
30
+ expect(Alchemy.user_class).to receive(:logged_in).and_return([another_user])
31
31
  end
32
32
 
33
33
  it "assigns @online_users" do
@@ -46,8 +46,8 @@ module Alchemy
46
46
 
47
47
  context 'user having signed in before' do
48
48
  before do
49
- user.should_receive(:sign_in_count).and_return(5)
50
- user.should_receive(:last_sign_in_at).and_return(Time.now)
49
+ expect(user).to receive(:sign_in_count).and_return(5)
50
+ expect(user).to receive(:last_sign_in_at).and_return(Time.now)
51
51
  end
52
52
 
53
53
  it "assigns @first_time" do
@@ -72,8 +72,8 @@ module Alchemy
72
72
  describe '#update_check' do
73
73
  context "if current Alchemy version equals the latest released version or it is newer" do
74
74
  before {
75
- controller.stub(:latest_alchemy_version).and_return('2.6')
76
- Alchemy.stub(:version).and_return("2.6")
75
+ allow(controller).to receive(:latest_alchemy_version).and_return('2.6')
76
+ allow(Alchemy).to receive(:version).and_return("2.6")
77
77
  }
78
78
 
79
79
  it "should render 'false'" do
@@ -84,8 +84,8 @@ module Alchemy
84
84
 
85
85
  context "if current Alchemy version is older than latest released version" do
86
86
  before {
87
- controller.stub(:latest_alchemy_version).and_return('2.6')
88
- Alchemy.stub(:version).and_return("2.5")
87
+ allow(controller).to receive(:latest_alchemy_version).and_return('2.6')
88
+ allow(Alchemy).to receive(:version).and_return("2.5")
89
89
  }
90
90
 
91
91
  it "should render 'true'" do
@@ -96,10 +96,10 @@ module Alchemy
96
96
 
97
97
  context "requesting rubygems.org" do
98
98
  before {
99
- Net::HTTP.any_instance.stub(:request).and_return(
99
+ allow_any_instance_of(Net::HTTP).to receive(:request).and_return(
100
100
  OpenStruct.new({code: '200', body: '[{"number": "2.6"}, {"number": "2.5"}]'})
101
101
  )
102
- Alchemy.stub(:version).and_return("2.6")
102
+ allow(Alchemy).to receive(:version).and_return("2.6")
103
103
  }
104
104
 
105
105
  it "should have response code of 200" do
@@ -110,8 +110,8 @@ module Alchemy
110
110
 
111
111
  context "requesting github.com" do
112
112
  before {
113
- controller.stub(:query_rubygems).and_return(OpenStruct.new({code: '503'}))
114
- Net::HTTP.any_instance.stub(:request).and_return(
113
+ allow(controller).to receive(:query_rubygems).and_return(OpenStruct.new({code: '503'}))
114
+ allow_any_instance_of(Net::HTTP).to receive(:request).and_return(
115
115
  OpenStruct.new({code: '200', body: '[{"name": "2.6"}, {"name": "2.5"}]'})
116
116
  )
117
117
  }
@@ -124,7 +124,7 @@ module Alchemy
124
124
 
125
125
  context "rubygems.org and github.com are unavailable" do
126
126
  before {
127
- Net::HTTP.any_instance.stub(:request).and_return(
127
+ allow_any_instance_of(Net::HTTP).to receive(:request).and_return(
128
128
  OpenStruct.new({code: '503'})
129
129
  )
130
130
  }
@@ -13,26 +13,30 @@ module Alchemy
13
13
  let(:alchemy_page) { build_stubbed(:page) }
14
14
 
15
15
  before do
16
- Page.stub(find: alchemy_page)
16
+ expect(Page).to receive(:find).and_return alchemy_page
17
17
  end
18
18
 
19
19
  context 'with cells' do
20
20
  let(:cell) { build_stubbed(:cell, page: alchemy_page) }
21
21
 
22
- before { alchemy_page.stub(cells: [cell]) }
22
+ before do
23
+ expect(alchemy_page).to receive(:cells).and_return [cell]
24
+ end
23
25
 
24
26
  it "groups elements by cell" do
25
- alchemy_page.should_receive(:elements_grouped_by_cells)
27
+ expect(alchemy_page).to receive(:elements_grouped_by_cells)
26
28
  get :index, {page_id: alchemy_page.id}
27
- assigns(:cells).should eq([cell])
29
+ expect(assigns(:cells)).to eq([cell])
28
30
  end
29
31
  end
30
32
 
31
33
  context 'without cells' do
32
- before { alchemy_page.stub(cells: []) }
34
+ before do
35
+ expect(alchemy_page).to receive(:cells).and_return []
36
+ end
33
37
 
34
38
  it "assigns page elements" do
35
- alchemy_page.should_receive(:elements).and_return(double(not_trashed: []))
39
+ expect(alchemy_page).to receive(:elements).and_return(double(not_trashed: []))
36
40
  get :index, {page_id: alchemy_page.id}
37
41
  end
38
42
  end
@@ -41,13 +45,9 @@ module Alchemy
41
45
  describe '#list' do
42
46
  let(:alchemy_page) { build_stubbed(:page) }
43
47
 
44
- before do
45
- Page.stub(find: alchemy_page)
46
- end
47
-
48
48
  context 'without page_id, but with page_urlname' do
49
49
  it "loads page from urlname" do
50
- Language.stub(:current).and_return(double(code: 'en', pages: double(find_by: double(id: 1001))))
50
+ expect(Language).to receive(:current).at_least(:once).and_return(double(code: 'en', pages: double(find_by: double(id: 1001))))
51
51
  xhr :get, :list, {page_urlname: 'contact'}
52
52
  end
53
53
 
@@ -56,7 +56,7 @@ module Alchemy
56
56
 
57
57
  it "should return a select tag with elements" do
58
58
  xhr :get, :list, {page_urlname: alchemy_page.urlname}
59
- response.body.should match(/select(.*)elements_from_page_selector(.*)option/)
59
+ expect(response.body).to match(/select(.*)elements_from_page_selector(.*)option/)
60
60
  end
61
61
  end
62
62
  end
@@ -64,7 +64,7 @@ module Alchemy
64
64
  context 'with page_id' do
65
65
  it "loads page from urlname" do
66
66
  xhr :get, :list, {page_id: alchemy_page.id}
67
- assigns(:page_id).should eq(alchemy_page.id.to_s)
67
+ expect(assigns(:page_id)).to eq(alchemy_page.id.to_s)
68
68
  end
69
69
  end
70
70
  end
@@ -93,22 +93,22 @@ module Alchemy
93
93
  expect(assigns(:trashed_elements).to_a).to eq [trashed_element.id]
94
94
  end
95
95
 
96
- it "should set a new position to the element" do
96
+ it "sets a new position to the element" do
97
97
  xhr :post, :order, element_ids: [trashed_element.id]
98
98
  trashed_element.reload
99
- trashed_element.position.should_not == nil
99
+ expect(trashed_element.position).to_not be_nil
100
100
  end
101
101
 
102
102
  it "should assign the (new) page_id to the element" do
103
103
  xhr :post, :order, element_ids: [trashed_element.id], page_id: 1, cell_id: nil
104
104
  trashed_element.reload
105
- trashed_element.page_id.should == 1
105
+ expect(trashed_element.page_id).to be 1
106
106
  end
107
107
 
108
108
  it "should assign the (new) cell_id to the element" do
109
109
  xhr :post, :order, element_ids: [trashed_element.id], page_id: 1, cell_id: 5
110
110
  trashed_element.reload
111
- trashed_element.cell_id.should == 5
111
+ expect(trashed_element.cell_id).to be 5
112
112
  end
113
113
  end
114
114
  end
@@ -116,10 +116,12 @@ module Alchemy
116
116
  describe '#new' do
117
117
  let(:alchemy_page) { build_stubbed(:page) }
118
118
 
119
- before { Page.stub(:find_by_id).and_return(alchemy_page) }
119
+ before do
120
+ expect(Page).to receive(:find_by_id).and_return(alchemy_page)
121
+ end
120
122
 
121
123
  it "assign variable for all available element definitions" do
122
- alchemy_page.should_receive(:available_element_definitions)
124
+ expect(alchemy_page).to receive(:available_element_definitions)
123
125
  get :new, {page_id: alchemy_page.id}
124
126
  end
125
127
 
@@ -129,9 +131,9 @@ module Alchemy
129
131
  before { clipboard['elements'] = clipboard_items }
130
132
 
131
133
  it "should load all elements from clipboard" do
132
- Element.should_receive(:all_from_clipboard_for_page).and_return(clipboard_items)
134
+ expect(Element).to receive(:all_from_clipboard_for_page).and_return(clipboard_items)
133
135
  get :new, {page_id: alchemy_page.id}
134
- assigns(:clipboard_items).should == clipboard_items
136
+ expect(assigns(:clipboard_items)).to eq(clipboard_items)
135
137
  end
136
138
  end
137
139
  end
@@ -142,13 +144,13 @@ module Alchemy
142
144
 
143
145
  it "should insert the element at bottom of list" do
144
146
  xhr :post, :create, {element: {name: 'news', page_id: alchemy_page.id}}
145
- alchemy_page.elements.count.should == 2
146
- alchemy_page.elements.last.name.should == 'news'
147
+ expect(alchemy_page.elements.count).to eq(2)
148
+ expect(alchemy_page.elements.last.name).to eq('news')
147
149
  end
148
150
 
149
151
  context "on a page with a setting for insert_elements_at of top" do
150
152
  before do
151
- PageLayout.stub(:get).and_return({
153
+ expect(PageLayout).to receive(:get).at_least(:once).and_return({
152
154
  'name' => 'news',
153
155
  'elements' => ['news'],
154
156
  'insert_elements_at' => 'top'
@@ -157,107 +159,120 @@ module Alchemy
157
159
 
158
160
  it "should insert the element at top of list" do
159
161
  xhr :post, :create, {element: {name: 'news', page_id: alchemy_page.id}}
160
- alchemy_page.elements.count.should == 2
161
- alchemy_page.elements.first.name.should == 'news'
162
+ expect(alchemy_page.elements.count).to eq(2)
163
+ expect(alchemy_page.elements.first.name).to eq('news')
162
164
  end
163
165
  end
164
166
  end
165
167
 
166
168
  context "if page has cells" do
167
- context "" do
168
- before do
169
- @page = create(:public_page, :do_not_autogenerate => false)
170
- @cell = create(:cell, :name => 'header', :page => @page)
171
- PageLayout.stub(:get).and_return({
172
- 'name' => 'standard',
173
- 'elements' => ['article'],
174
- 'cells' => ['header']
175
- })
176
- Cell.stub(:definition_for).and_return({'name' => 'header', 'elements' => ['article']})
177
- end
169
+ let(:page) { create(:public_page, do_not_autogenerate: false) }
170
+ let(:cell) { page.cells.first }
178
171
 
172
+ context "not pasting from clipboard" do
179
173
  context "and cell name in element name" do
174
+ before do
175
+ expect(PageLayout).to receive(:get).at_least(:once).and_return({
176
+ 'name' => 'standard',
177
+ 'elements' => ['article'],
178
+ 'cells' => ['header']
179
+ })
180
+ expect(Cell).to receive(:definition_for).and_return({
181
+ 'name' => 'header',
182
+ 'elements' => ['article']
183
+ })
184
+ end
185
+
180
186
  it "should put the element in the correct cell" do
181
- xhr :post, :create, {:element => {:name => "article#header", :page_id => @page.id}}
182
- @cell.elements.first.should be_an_instance_of(Element)
187
+ xhr :post, :create, {element: {name: "article#header", page_id: page.id}}
188
+ expect(cell.elements.first).to be_an_instance_of(Element)
183
189
  end
184
190
  end
185
191
 
186
192
  context "and no cell name in element name" do
187
193
  it "should put the element in the main cell" do
188
- xhr :post, :create, {:element => {:name => "article", :page_id => @page.id}}
189
- @page.elements.not_in_cell.first.should be_an_instance_of(Element)
194
+ xhr :post, :create, {element: {name: "article", page_id: page.id}}
195
+ expect(page.elements.not_in_cell.first).to be_an_instance_of(Element)
190
196
  end
191
197
  end
192
198
  end
193
199
 
194
- context "with paste_from_clipboard in parameters" do
195
- context "" do
200
+ context "pasting from clipboard" do
201
+ context "with default element insert position" do
196
202
  before do
197
- @page = create(:public_page, :do_not_autogenerate => false)
198
- @cell = create(:cell, :name => 'header', :page => @page)
199
- PageLayout.stub(:get).and_return({
203
+ expect(PageLayout).to receive(:get).at_least(:once).and_return({
200
204
  'name' => 'standard',
201
205
  'elements' => ['article'],
202
206
  'cells' => ['header']
203
207
  })
204
- Cell.stub(:definition_for).and_return({'name' => 'header', 'elements' => ['article']})
205
208
  clipboard['elements'] = [{'id' => element_in_clipboard.id.to_s}]
206
209
  end
207
210
 
208
211
  context "and cell name in element name" do
212
+ before do
213
+ expect(Cell).to receive(:definition_for).at_least(:once).and_return({
214
+ 'name' => 'header',
215
+ 'elements' => ['article']
216
+ })
217
+ end
218
+
209
219
  it "should create the element in the correct cell" do
210
- xhr :post, :create, {:element => {:page_id => @page.id}, :paste_from_clipboard => "#{element_in_clipboard.id}##{@cell.name}"}
211
- @cell.elements.first.should be_an_instance_of(Element)
220
+ xhr :post, :create, {element: {page_id: page.id}, paste_from_clipboard: "#{element_in_clipboard.id}##{cell.name}"}
221
+ expect(cell.elements.first).to be_an_instance_of(Element)
212
222
  end
213
- end
214
223
 
215
- context "and no cell name in element name" do
216
- it "should create the element in the nil cell" do
217
- xhr :post, :create, {:element => {:page_id => @page.id}, :paste_from_clipboard => "#{element_in_clipboard.id}"}
218
- @page.elements.first.cell.should == nil
224
+ context "with elements already in cell" do
225
+ before do
226
+ cell.elements.create(page_id: page.id, name: "article", create_contents_after_create: false)
227
+ end
228
+
229
+ it "should set the correct position for the element" do
230
+ xhr :post, :create, {element: {page_id: page.id}, paste_from_clipboard: "#{element_in_clipboard.id}##{cell.name}"}
231
+ expect(cell.elements.last.position).to eq(cell.elements.count)
232
+ end
219
233
  end
220
234
  end
221
235
 
222
- context "" do
223
- before { @cell.elements.create(:page_id => @page.id, :name => "article", :create_contents_after_create => false) }
224
-
225
- it "should set the correct position for the element" do
226
- xhr :post, :create, {:element => {:page_id => @page.id}, :paste_from_clipboard => "#{element_in_clipboard.id}##{@cell.name}"}
227
- @cell.elements.last.position.should == @cell.elements.count
236
+ context "and no cell name in element name" do
237
+ it "should create the element in the nil cell" do
238
+ xhr :post, :create, {element: {page_id: page.id}, paste_from_clipboard: "#{element_in_clipboard.id}"}
239
+ expect(page.elements.first.cell).to eq(nil)
228
240
  end
229
241
  end
230
242
  end
231
243
 
232
244
  context "on a page with a setting for insert_elements_at of top" do
233
- let(:alchemy_page) { create(:public_page, :name => 'News') }
234
- let(:element_in_clipboard) { create(:element, :page => alchemy_page, :name => 'news') }
235
- let(:cell) { alchemy_page.cells.first }
236
- let(:element) { create(:element, :name => 'news', :page => alchemy_page, :cell => cell) }
245
+ let!(:alchemy_page) { create(:public_page, name: 'News') }
246
+ let!(:element_in_clipboard) { create(:element, page: alchemy_page, name: 'news') }
247
+ let!(:cell) { create(:cell, name: 'news', page: alchemy_page) }
248
+ let!(:element) { create(:element, name: 'news', page: alchemy_page, cell: cell) }
237
249
 
238
250
  before do
239
- PageLayout.stub(:get).and_return({
251
+ expect(PageLayout).to receive(:get).at_least(:once).and_return({
240
252
  'name' => 'news',
241
253
  'elements' => ['news'],
242
254
  'insert_elements_at' => 'top',
243
255
  'cells' => ['news']
244
256
  })
245
- Cell.stub(:definition_for).and_return({'name' => 'news', 'elements' => ['news']})
257
+ expect(Cell).to receive(:definition_for).and_return({
258
+ 'name' => 'news',
259
+ 'elements' => ['news']
260
+ })
246
261
  clipboard['elements'] = [{'id' => element_in_clipboard.id.to_s}]
247
262
  cell.elements << element
248
263
  end
249
264
 
250
265
  it "should insert the element at top of list" do
251
- xhr :post, :create, {:element => {:name => 'news', :page_id => alchemy_page.id}, :paste_from_clipboard => "#{element_in_clipboard.id}##{cell.name}"}
252
- cell.elements.count.should == 2
253
- cell.elements.first.name.should == 'news'
254
- cell.elements.first.should_not == element
266
+ xhr :post, :create, {element: {name: 'news', page_id: alchemy_page.id}, paste_from_clipboard: "#{element_in_clipboard.id}##{cell.name}"}
267
+ expect(cell.elements.count).to eq(2)
268
+ expect(cell.elements.first.name).to eq('news')
269
+ expect(cell.elements.first).not_to eq(element)
255
270
  end
256
271
  end
257
272
  end
258
273
  end
259
274
 
260
- context "with paste_from_clipboard in parameters" do
275
+ context "pasting from clipboard" do
261
276
  render_views
262
277
 
263
278
  before do
@@ -266,14 +281,14 @@ module Alchemy
266
281
 
267
282
  it "should create an element from clipboard" do
268
283
  xhr :post, :create, {paste_from_clipboard: element_in_clipboard.id, element: {page_id: alchemy_page.id}}
269
- response.status.should == 200
270
- response.body.should match(/Successfully added new element/)
284
+ expect(response.status).to eq(200)
285
+ expect(response.body).to match(/Successfully added new element/)
271
286
  end
272
287
 
273
288
  context "and with cut as action parameter" do
274
289
  it "should also remove the element id from clipboard" do
275
290
  xhr :post, :create, {paste_from_clipboard: element_in_clipboard.id, element: {page_id: alchemy_page.id}}
276
- session[:alchemy_clipboard]['elements'].detect { |item| item['id'] == element_in_clipboard.id.to_s }.should be_nil
291
+ expect(session[:alchemy_clipboard]['elements'].detect { |item| item['id'] == element_in_clipboard.id.to_s }).to be_nil
277
292
  end
278
293
  end
279
294
  end
@@ -281,7 +296,9 @@ module Alchemy
281
296
  context 'if element could not be saved' do
282
297
  subject { post :create, {element: {page_id: alchemy_page.id}} }
283
298
 
284
- before { Element.any_instance.stub(save: false) }
299
+ before do
300
+ expect_any_instance_of(Element).to receive(:save).and_return false
301
+ end
285
302
 
286
303
  it "renders the new template" do
287
304
  expect(subject).to render_template(:new)
@@ -291,13 +308,16 @@ module Alchemy
291
308
 
292
309
  describe '#find_or_create_cell' do
293
310
  before do
294
- Cell.stub(:definition_for).and_return({'name' => 'header', 'elements' => ['header']})
295
311
  controller.instance_variable_set(:@page, alchemy_page)
296
312
  end
297
313
 
298
314
  context "with element name and cell name in the params" do
299
315
  before do
300
- controller.stub(params: {element: {name: 'header#header'}})
316
+ expect(Cell).to receive(:definition_for).and_return({
317
+ 'name' => 'header',
318
+ 'elements' => ['header']
319
+ })
320
+ expect(controller).to receive(:params).and_return({element: {name: 'header#header'}})
301
321
  end
302
322
 
303
323
  context "with cell not existing" do
@@ -323,18 +343,18 @@ module Alchemy
323
343
 
324
344
  context "with only the element name in the params" do
325
345
  before do
326
- controller.stub(params: {element: {name: 'header'}})
346
+ expect(controller).to receive(:params).and_return({element: {name: 'header'}})
327
347
  end
328
348
 
329
349
  it "should return nil" do
330
- controller.send(:find_or_create_cell).should be_nil
350
+ expect(controller.send(:find_or_create_cell)).to be_nil
331
351
  end
332
352
  end
333
353
 
334
354
  context 'with cell definition not found' do
335
355
  before do
336
- controller.stub(params: {element: {name: 'header#header'}})
337
- Cell.stub(definition_for: nil)
356
+ expect(controller).to receive(:params).and_return({element: {name: 'header#header'}})
357
+ expect(Cell).to receive(:definition_for).and_return nil
338
358
  end
339
359
 
340
360
  it "raises error" do
@@ -350,27 +370,27 @@ module Alchemy
350
370
  let(:element_parameters) { ActionController::Parameters.new(tag_list: 'Tag 1', public: false) }
351
371
 
352
372
  before do
353
- Element.stub(:find).and_return element
354
- controller.should_receive(:contents_params).and_return(contents_parameters)
373
+ expect(Element).to receive(:find).and_return element
374
+ expect(controller).to receive(:contents_params).and_return(contents_parameters)
355
375
  end
356
376
 
357
377
  it "updates all contents in element" do
358
- element.should_receive(:update_contents).with(contents_parameters)
378
+ expect(element).to receive(:update_contents).with(contents_parameters)
359
379
  xhr :put, :update, {id: element.id}
360
380
  end
361
381
 
362
382
  it "updates the element" do
363
- controller.should_receive(:element_params).and_return(element_parameters)
364
- element.should_receive(:update_contents).and_return(true)
365
- element.should_receive(:update_attributes!).with(element_parameters).and_return(true)
383
+ expect(controller).to receive(:element_params).and_return(element_parameters)
384
+ expect(element).to receive(:update_contents).and_return(true)
385
+ expect(element).to receive(:update_attributes!).with(element_parameters).and_return(true)
366
386
  xhr :put, :update, {id: element.id}
367
387
  end
368
388
 
369
389
  context "failed validations" do
370
390
  it "displays validation failed notice" do
371
- element.should_receive(:update_contents).and_return(false)
391
+ expect(element).to receive(:update_contents).and_return(false)
372
392
  xhr :put, :update, {id: element.id}
373
- assigns(:element_validated).should be_false
393
+ expect(assigns(:element_validated)).to be_falsey
374
394
  end
375
395
  end
376
396
  end
@@ -380,14 +400,14 @@ module Alchemy
380
400
  let(:parameters) { ActionController::Parameters.new(contents: {1 => {ingredient: 'Title'}}) }
381
401
 
382
402
  specify ":contents is required" do
383
- controller.params.should_receive(:fetch).and_return(parameters)
403
+ expect(controller.params).to receive(:fetch).and_return(parameters)
384
404
  controller.send :contents_params
385
405
  end
386
406
 
387
407
  specify "everything is permitted" do
388
- controller.should_receive(:params).and_return(parameters)
389
- parameters.should_receive(:fetch).and_return(parameters)
390
- parameters.should_receive(:permit!)
408
+ expect(controller).to receive(:params).and_return(parameters)
409
+ expect(parameters).to receive(:fetch).and_return(parameters)
410
+ expect(parameters).to receive(:permit!)
391
411
  controller.send :contents_params
392
412
  end
393
413
  end
@@ -396,14 +416,14 @@ module Alchemy
396
416
  let(:parameters) { ActionController::Parameters.new(element: {public: true}) }
397
417
 
398
418
  specify ":element is required" do
399
- controller.params.should_receive(:require).with(:element).and_return(parameters)
419
+ expect(controller.params).to receive(:require).with(:element).and_return(parameters)
400
420
  controller.send :element_params
401
421
  end
402
422
 
403
423
  specify ":public and :tag_list is permitted" do
404
- controller.should_receive(:params).and_return(parameters)
405
- parameters.should_receive(:require).with(:element).and_return(parameters)
406
- parameters.should_receive(:permit).with(:public, :tag_list)
424
+ expect(controller).to receive(:params).and_return(parameters)
425
+ expect(parameters).to receive(:require).with(:element).and_return(parameters)
426
+ expect(parameters).to receive(:permit).with(:public, :tag_list)
407
427
  controller.send :element_params
408
428
  end
409
429
  end
@@ -414,10 +434,10 @@ module Alchemy
414
434
 
415
435
  let(:element) { build_stubbed(:element) }
416
436
 
417
- before { Element.stub(find: element) }
437
+ before { expect(Element).to receive(:find).and_return element }
418
438
 
419
439
  it "trashes the element instead of deleting it" do
420
- element.should_receive(:trash!).and_return(true)
440
+ expect(element).to receive(:trash!).and_return(true)
421
441
  subject
422
442
  end
423
443
  end
@@ -428,24 +448,24 @@ module Alchemy
428
448
  let(:element) { build_stubbed(:element) }
429
449
 
430
450
  before do
431
- element.stub(save: true)
432
- Element.stub(find: element)
451
+ expect(element).to receive(:save).and_return true
452
+ expect(Element).to receive(:find).and_return element
433
453
  end
434
454
 
435
455
  context 'if element is folded' do
436
- before { element.stub(folded: true) }
456
+ before { expect(element).to receive(:folded).and_return true }
437
457
 
438
458
  it "sets folded to false." do
439
- element.should_receive(:folded=).with(false).and_return(true)
459
+ expect(element).to receive(:folded=).with(false).and_return(true)
440
460
  subject
441
461
  end
442
462
  end
443
463
 
444
464
  context 'if element is not folded' do
445
- before { element.stub(folded: false) }
465
+ before { expect(element).to receive(:folded).and_return false }
446
466
 
447
467
  it "sets folded to true." do
448
- element.should_receive(:folded=).with(true).and_return(true)
468
+ expect(element).to receive(:folded=).with(true).and_return(true)
449
469
  subject
450
470
  end
451
471
  end