alchemy_cms 2.6.3 → 2.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (246) hide show
  1. checksums.yaml +4 -4
  2. data/.simplecov +14 -0
  3. data/.travis.yml +1 -1
  4. data/Gemfile +7 -6
  5. data/README.md +15 -5
  6. data/alchemy_cms.gemspec +3 -2
  7. data/app/assets/javascripts/alchemy/alchemy.base.js.coffee +9 -17
  8. data/app/assets/javascripts/alchemy/alchemy.dirty.js.coffee +70 -0
  9. data/app/assets/javascripts/alchemy/alchemy.dragndrop.js.coffee +80 -0
  10. data/app/assets/javascripts/alchemy/alchemy.element_editors.js.coffee +43 -19
  11. data/app/assets/javascripts/alchemy/alchemy.gui.js.coffee +3 -1
  12. data/app/assets/javascripts/alchemy/alchemy.js +4 -2
  13. data/app/assets/javascripts/alchemy/alchemy.onload.js.coffee +1 -1
  14. data/app/assets/javascripts/alchemy/alchemy.spinner.js.coffee +14 -0
  15. data/app/assets/javascripts/alchemy/alchemy.tinymce.js.coffee.erb +96 -0
  16. data/app/assets/javascripts/alchemy/alchemy.translations.js.coffee +22 -0
  17. data/app/assets/javascripts/alchemy/alchemy.windows.js.coffee +28 -17
  18. data/app/assets/stylesheets/alchemy/base.scss +6 -0
  19. data/app/assets/stylesheets/alchemy/elements.scss +2 -28
  20. data/app/assets/stylesheets/alchemy/errors.scss +1 -1
  21. data/app/assets/stylesheets/alchemy/menubar.css.scss +2 -0
  22. data/app/assets/stylesheets/alchemy/sitemap.scss +21 -34
  23. data/app/assets/stylesheets/alchemy/tables.scss +13 -3
  24. data/app/controllers/alchemy/admin/attachments_controller.rb +10 -5
  25. data/app/controllers/alchemy/admin/base_controller.rb +19 -0
  26. data/app/controllers/alchemy/admin/contents_controller.rb +1 -4
  27. data/app/controllers/alchemy/admin/dashboard_controller.rb +2 -1
  28. data/app/controllers/alchemy/admin/elements_controller.rb +1 -1
  29. data/app/controllers/alchemy/admin/essence_files_controller.rb +1 -1
  30. data/app/controllers/alchemy/admin/essence_pictures_controller.rb +70 -56
  31. data/app/controllers/alchemy/admin/pages_controller.rb +37 -114
  32. data/app/controllers/alchemy/admin/pictures_controller.rb +5 -12
  33. data/app/controllers/alchemy/admin/resources_controller.rb +3 -1
  34. data/app/controllers/alchemy/admin/trash_controller.rb +1 -1
  35. data/app/controllers/alchemy/attachments_controller.rb +1 -1
  36. data/app/controllers/alchemy/base_controller.rb +3 -15
  37. data/app/controllers/alchemy/messages_controller.rb +4 -10
  38. data/app/controllers/alchemy/pages_controller.rb +6 -6
  39. data/app/controllers/alchemy/passwords_controller.rb +1 -1
  40. data/app/controllers/alchemy/user_sessions_controller.rb +1 -1
  41. data/app/helpers/alchemy/admin/base_helper.rb +49 -230
  42. data/app/helpers/alchemy/admin/contents_helper.rb +5 -1
  43. data/app/helpers/alchemy/admin/elements_helper.rb +19 -47
  44. data/app/helpers/alchemy/admin/essences_helper.rb +59 -17
  45. data/app/helpers/alchemy/admin/navigation_helper.rb +204 -0
  46. data/app/helpers/alchemy/admin/pages_helper.rb +22 -79
  47. data/app/helpers/alchemy/admin/pictures_helper.rb +1 -1
  48. data/app/helpers/alchemy/admin/tags_helper.rb +42 -0
  49. data/app/helpers/alchemy/base_helper.rb +0 -11
  50. data/app/helpers/alchemy/elements_helper.rb +48 -25
  51. data/app/helpers/alchemy/essences_helper.rb +0 -20
  52. data/app/helpers/alchemy/pages_helper.rb +18 -14
  53. data/app/helpers/alchemy/url_helper.rb +1 -0
  54. data/app/mailers/alchemy/messages.rb +4 -6
  55. data/app/models/alchemy/attachment.rb +3 -0
  56. data/app/models/alchemy/cell.rb +33 -35
  57. data/app/models/alchemy/content.rb +20 -111
  58. data/app/models/alchemy/content/factory.rb +188 -0
  59. data/app/models/alchemy/element.rb +51 -200
  60. data/app/models/alchemy/element/definitions.rb +52 -0
  61. data/app/models/alchemy/element/presenters.rb +87 -0
  62. data/app/models/alchemy/essence_date.rb +1 -1
  63. data/app/models/alchemy/essence_file.rb +6 -7
  64. data/app/models/alchemy/essence_picture.rb +19 -4
  65. data/app/models/alchemy/message.rb +18 -14
  66. data/app/models/alchemy/page.rb +120 -214
  67. data/app/models/alchemy/page/elements.rb +145 -36
  68. data/app/models/alchemy/page/natures.rb +90 -0
  69. data/app/models/alchemy/page/scopes.rb +93 -0
  70. data/app/models/alchemy/page/users.rb +25 -0
  71. data/app/models/alchemy/picture.rb +15 -0
  72. data/app/models/alchemy/site.rb +15 -1
  73. data/app/models/alchemy/site/layout.rb +38 -0
  74. data/app/models/alchemy/user.rb +13 -3
  75. data/app/views/alchemy/admin/attachments/_archive_overlay.html.erb +7 -7
  76. data/app/views/alchemy/admin/attachments/_file_to_assign.html.erb +8 -8
  77. data/app/views/alchemy/admin/attachments/_tag_list.html.erb +1 -16
  78. data/app/views/alchemy/admin/attachments/destroy.js.erb +1 -4
  79. data/app/views/alchemy/admin/contents/create.js.erb +1 -1
  80. data/app/views/alchemy/admin/dashboard/index.html.erb +14 -13
  81. data/app/views/alchemy/admin/elements/_element_head.html.erb +7 -7
  82. data/app/views/alchemy/admin/elements/_refresh_editor.js.erb +10 -0
  83. data/app/views/alchemy/admin/elements/create.js.erb +44 -44
  84. data/app/views/alchemy/admin/elements/fold.js.erb +22 -26
  85. data/app/views/alchemy/admin/elements/trash.js.erb +1 -1
  86. data/app/views/alchemy/admin/elements/update.js.erb +22 -25
  87. data/app/views/alchemy/admin/essence_files/assign.js.erb +8 -3
  88. data/app/views/alchemy/admin/essence_pictures/crop.html.erb +14 -12
  89. data/app/views/alchemy/admin/essence_pictures/edit.html.erb +22 -39
  90. data/app/views/alchemy/admin/pages/_page.html.erb +73 -80
  91. data/app/views/alchemy/admin/pages/destroy.js.erb +2 -2
  92. data/app/views/alchemy/admin/pages/edit.html.erb +21 -18
  93. data/app/views/alchemy/admin/pages/fold.js.erb +1 -0
  94. data/app/views/alchemy/admin/pages/info.html.erb +32 -0
  95. data/app/views/alchemy/admin/partials/_main_navigation_entry.html.erb +11 -13
  96. data/app/views/alchemy/admin/partials/_remote_search_form.html.erb +20 -20
  97. data/app/views/alchemy/admin/partials/_sub_navigation.html.erb +8 -0
  98. data/app/views/alchemy/admin/partials/_toolbar_button.html.erb +25 -0
  99. data/app/views/alchemy/admin/partials/_upload_form.html.erb +15 -15
  100. data/app/views/alchemy/admin/pictures/_filter_and_size_bar.html.erb +39 -39
  101. data/app/views/alchemy/admin/pictures/_picture_to_assign.html.erb +10 -10
  102. data/app/views/alchemy/admin/pictures/_tag_list.html.erb +1 -16
  103. data/app/views/alchemy/admin/resources/destroy.js.erb +1 -1
  104. data/app/views/alchemy/base/500.html.erb +1 -1
  105. data/app/views/alchemy/base/permission_denied.js.erb +1 -1
  106. data/app/views/alchemy/base/redirect.js.erb +1 -1
  107. data/app/views/alchemy/essences/_essence_link_editor.html.erb +1 -1
  108. data/app/views/alchemy/essences/_essence_picture_editor.html.erb +1 -1
  109. data/app/views/alchemy/essences/_essence_richtext_editor.html.erb +1 -1
  110. data/app/views/alchemy/essences/_essence_text_editor.html.erb +1 -1
  111. data/app/views/alchemy/essences/{_essence_picture_tools.html.erb → shared/_essence_picture_tools.html.erb} +5 -5
  112. data/app/views/alchemy/essences/{_linkable_essence_tools.html.erb → shared/_linkable_essence_tools.html.erb} +0 -0
  113. data/app/views/alchemy/messages/contact_form_mail.de.text.erb +12 -0
  114. data/app/views/alchemy/messages/contact_form_mail.en.text.erb +12 -0
  115. data/app/views/alchemy/notifications/reset_password_instructions.de.text.erb +1 -1
  116. data/app/views/alchemy/notifications/reset_password_instructions.en.text.erb +2 -2
  117. data/app/views/alchemy/pages/sitemap.xml.erb +3 -5
  118. data/app/views/alchemy/user_sessions/leave.html.erb +1 -1
  119. data/app/views/layouts/alchemy/admin.html.erb +4 -2
  120. data/app/views/layouts/alchemy/sitemap.xml.erb +1 -1
  121. data/bin/alchemy +7 -13
  122. data/config/alchemy/config.yml +1 -0
  123. data/config/authorization_rules.rb +2 -3
  124. data/config/initializers/dragonfly.rb +2 -0
  125. data/config/locales/alchemy.de.yml +8 -9
  126. data/config/locales/alchemy.en.yml +7 -4
  127. data/config/routes.rb +3 -0
  128. data/db/migrate/{20130214233001_alchemy_two_point_five.rb → 20130827094554_alchemy_two_point_six.rb} +29 -6
  129. data/lib/alchemy/auth/engine.rb +9 -0
  130. data/lib/alchemy/capistrano.rb +37 -12
  131. data/lib/alchemy/config.rb +48 -35
  132. data/lib/alchemy/engine.rb +35 -6
  133. data/lib/alchemy/essence.rb +25 -29
  134. data/lib/alchemy/ferret/search.rb +86 -0
  135. data/lib/alchemy/{scoped_pagination_url_helper.rb → kaminari/scoped_pagination_url_helper.rb} +0 -0
  136. data/lib/alchemy/logger.rb +3 -4
  137. data/lib/alchemy/page_layout.rb +124 -55
  138. data/lib/alchemy/resource.rb +0 -10
  139. data/lib/alchemy/resources_helper.rb +0 -5
  140. data/lib/alchemy/seeder.rb +1 -32
  141. data/lib/alchemy/shell.rb +6 -1
  142. data/lib/alchemy/tinymce.rb +41 -32
  143. data/lib/alchemy/upgrader.rb +3 -1
  144. data/lib/alchemy/upgrader/two_point_five.rb +15 -8
  145. data/lib/alchemy/upgrader/two_point_one.rb +10 -10
  146. data/lib/alchemy/upgrader/two_point_two.rb +96 -51
  147. data/lib/alchemy/version.rb +1 -1
  148. data/lib/alchemy_cms.rb +5 -46
  149. data/lib/rails/generators/alchemy/deploy_script/templates/deploy.rb.tt +1 -1
  150. data/lib/rails/generators/alchemy/devise/devise_generator.rb +9 -4
  151. data/lib/rails/generators/alchemy/essence/essence_generator.rb +7 -6
  152. data/lib/rails/generators/alchemy/essence/templates/editor.html.erb +1 -1
  153. data/lib/rails/generators/alchemy/scaffold/files/_standard.html.erb +1 -0
  154. data/lib/rails/generators/alchemy/scaffold/scaffold_generator.rb +1 -0
  155. data/lib/rails/generators/alchemy/site_layouts/site_layouts_generator.rb +23 -0
  156. data/lib/rails/generators/alchemy/site_layouts/templates/layout.html.erb +1 -0
  157. data/lib/rails/generators/alchemy/site_layouts/templates/layout.html.haml +1 -0
  158. data/lib/rails/generators/alchemy/site_layouts/templates/layout.html.slim +1 -0
  159. data/lib/rails/templates/alchemy.rb +2 -2
  160. data/lib/tasks/alchemy/db.rake +3 -1
  161. data/lib/tasks/alchemy/tidy.rake +82 -0
  162. data/lib/tasks/alchemy/upgrade.rake +2 -1
  163. data/spec/controllers/admin/attachments_controller_spec.rb +124 -0
  164. data/spec/controllers/admin/base_controller_spec.rb +35 -0
  165. data/spec/controllers/admin/clipboard_controller_spec.rb +1 -1
  166. data/spec/controllers/admin/contents_controller_spec.rb +17 -26
  167. data/spec/controllers/admin/dashboard_controller_spec.rb +121 -0
  168. data/spec/controllers/admin/elements_controller_spec.rb +1 -1
  169. data/spec/controllers/admin/essence_files_controller_spec.rb +67 -0
  170. data/spec/controllers/admin/essence_pictures_controller_spec.rb +161 -0
  171. data/spec/controllers/admin/languages_controller_spec.rb +1 -1
  172. data/spec/controllers/admin/layoutpages_controller_spec.rb +28 -0
  173. data/spec/controllers/admin/pages_controller_spec.rb +164 -118
  174. data/spec/controllers/admin/pictures_controller_spec.rb +89 -0
  175. data/spec/controllers/admin/trash_controller_spec.rb +21 -31
  176. data/spec/controllers/admin/users_controller_spec.rb +114 -85
  177. data/spec/controllers/attachments_controller_spec.rb +6 -2
  178. data/spec/controllers/base_controller_spec.rb +22 -0
  179. data/spec/controllers/elements_controller_spec.rb +1 -1
  180. data/spec/controllers/messages_controller_spec.rb +200 -0
  181. data/spec/controllers/pictures_controller_spec.rb +1 -1
  182. data/spec/controllers/user_sessions_controller_spec.rb +7 -6
  183. data/spec/controllers/users_controller_spec.rb +2 -2
  184. data/spec/dummy/config/alchemy/cells.yml +2 -0
  185. data/spec/dummy/config/application.rb +19 -8
  186. data/spec/dummy/db/migrate/{20130214233001_alchemy_two_point_five.rb → 20130827094554_alchemy_two_point_six.rb} +29 -6
  187. data/spec/dummy/db/schema.rb +1 -1
  188. data/spec/fast_specs.rb +15 -0
  189. data/spec/helpers/admin/base_helper_spec.rb +53 -34
  190. data/spec/helpers/admin/contents_helper_spec.rb +15 -7
  191. data/spec/helpers/admin/elements_helper_spec.rb +79 -34
  192. data/spec/helpers/admin/essences_helper_spec.rb +45 -31
  193. data/spec/helpers/admin/navigation_helper_spec.rb +204 -0
  194. data/spec/helpers/admin/pages_helper_spec.rb +25 -15
  195. data/spec/helpers/admin/tags_helper_spec.rb +62 -2
  196. data/spec/helpers/elements_helper_spec.rb +202 -138
  197. data/spec/helpers/pages_helper_spec.rb +48 -0
  198. data/spec/helpers/url_helper_spec.rb +7 -0
  199. data/spec/libraries/config_spec.rb +110 -3
  200. data/spec/libraries/essence_spec.rb +29 -9
  201. data/spec/libraries/page_layout_spec.rb +134 -0
  202. data/spec/libraries/resource_spec.rb +3 -16
  203. data/spec/libraries/resources_helper_spec.rb +4 -8
  204. data/spec/libraries/shell_spec.rb +1 -0
  205. data/spec/libraries/tinymce_spec.rb +61 -0
  206. data/spec/mailers/messages_spec.rb +23 -0
  207. data/spec/models/attachment_spec.rb +45 -0
  208. data/spec/models/cell_spec.rb +62 -9
  209. data/spec/models/content_spec.rb +110 -28
  210. data/spec/models/element_spec.rb +275 -253
  211. data/spec/models/essence_date_spec.rb +25 -0
  212. data/spec/models/essence_file_spec.rb +23 -0
  213. data/spec/models/essence_html_spec.rb +13 -0
  214. data/spec/models/essence_picture_spec.rb +16 -0
  215. data/spec/models/essence_text_spec.rb +29 -0
  216. data/spec/models/language_spec.rb +34 -0
  217. data/spec/models/message_spec.rb +43 -0
  218. data/spec/models/page_spec.rb +726 -567
  219. data/spec/models/picture_spec.rb +98 -0
  220. data/spec/models/site_spec.rb +60 -2
  221. data/spec/models/tag_spec.rb +31 -0
  222. data/spec/models/user_spec.rb +4 -4
  223. data/spec/spec_helper.rb +49 -58
  224. data/spec/support/alchemy/controller_helpers.rb +35 -0
  225. data/spec/support/alchemy/{specs_helpers.rb → integration_helpers.rb} +4 -8
  226. data/spec/{factories.rb → support/factories.rb} +11 -1
  227. data/vendor/assets/javascripts/jquery_plugins/jquery.ui.nestedSortable.js +2 -8
  228. metadata +166 -106
  229. data/Guardfile +0 -16
  230. data/app/assets/javascripts/alchemy/alchemy.dirty.js +0 -93
  231. data/app/assets/javascripts/alchemy/alchemy.dragndrop.js +0 -122
  232. data/app/models/alchemy/tree_node.rb +0 -4
  233. data/app/views/alchemy/admin/pages/_page_infos.html.erb +0 -3
  234. data/app/views/alchemy/admin/partials/_sub_navigation_tab.html.erb +0 -8
  235. data/app/views/alchemy/messages/contact_form_mail.text.erb +0 -12
  236. data/config/initializers/kaminari_config.rb +0 -9
  237. data/db/migrate/20130221200514_migrate_attachments_to_dragonfly.rb +0 -21
  238. data/db/migrate/20130312205327_change_alchemy_users_role_to_roles.rb +0 -11
  239. data/lib/alchemy/auth_engine.rb +0 -7
  240. data/lib/alchemy/authentication_helpers.rb +0 -9
  241. data/lib/alchemy/ferret_search.rb +0 -84
  242. data/lib/extensions/array.rb +0 -25
  243. data/lib/extensions/hash.rb +0 -34
  244. data/spec/dummy/db/migrate/20130221200514_migrate_attachments_to_dragonfly.rb +0 -21
  245. data/spec/dummy/db/migrate/20130312205327_change_alchemy_users_role_to_roles.rb +0 -11
  246. data/spec/models/page_layout_spec.rb +0 -60
@@ -8,7 +8,7 @@ module Alchemy
8
8
  let(:another_element) { FactoryGirl.create(:element, :page => public_page) }
9
9
 
10
10
  before do
11
- sign_in :user, FactoryGirl.create(:admin_user)
11
+ sign_in(admin_user)
12
12
  session[:clipboard] = Clipboard.new
13
13
  end
14
14
 
@@ -1,51 +1,42 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Alchemy::Admin::ContentsController do
4
+ before { sign_in(admin_user) }
4
5
 
5
- before(:each) do
6
- sign_in :user, FactoryGirl.create(:admin_user)
7
- end
6
+ let(:element) { FactoryGirl.create(:element, create_contents_after_create: true) }
8
7
 
9
8
  describe '#create' do
9
+ let(:element) { FactoryGirl.create(:element, name: 'headline') }
10
10
 
11
- let(:element) { FactoryGirl.create(:element, :name => 'headline') }
12
-
13
- it "should create a content via ajax post" do
14
- length_before = element.contents.length
15
- post :create, {:content => {:element_id => element.id, :name => 'headline'}, :format => :js}
16
- element.contents.reload
17
- element.contents.length.should == length_before + 1
11
+ it "creates a content from name" do
12
+ expect {
13
+ xhr :post, :create, {content: {element_id: element.id, name: 'headline'}}
14
+ }.to change{element.contents.count}.by(1)
18
15
  end
19
16
 
17
+ it "creates a content from essence_type" do
18
+ expect {
19
+ xhr :post, :create, {content: {element_id: element.id, essence_type: 'EssencePicture'}}
20
+ }.to change{element.contents.count}.by(1)
21
+ end
20
22
  end
21
23
 
22
24
  describe '#update' do
23
-
24
25
  it "should update a content via ajax" do
25
- @element = FactoryGirl.create(:element, :create_contents_after_create => true)
26
- post :update, {:id => @element.contents.find_by_name('intro').id, :content => {:body => 'Peters Petshop'}, :format => :js}
27
- @element.ingredient('intro').should == "Peters Petshop"
26
+ xhr :post, :update, {id: element.contents.find_by_name('intro').id, content: {body: 'Peters Petshop'}}
27
+ element.ingredient('intro').should == "Peters Petshop"
28
28
  end
29
-
30
29
  end
31
30
 
32
31
  describe "#order" do
33
-
34
32
  context "with content_ids in params" do
35
-
36
- before(:each) do
37
- @element = FactoryGirl.create(:element, :create_contents_after_create => true)
38
- end
39
-
40
33
  it "should reorder the contents" do
41
- content_ids = @element.contents.essence_texts.collect(&:id)
42
- post :order, {:content_ids => content_ids.reverse, :format => :js}
34
+ content_ids = element.contents.essence_texts.collect(&:id)
35
+ xhr :post, :order, {content_ids: content_ids.reverse}
43
36
  response.status.should == 200
44
- @element.contents.essence_texts.collect(&:id).should == content_ids.reverse
37
+ element.contents.essence_texts.collect(&:id).should == content_ids.reverse
45
38
  end
46
-
47
39
  end
48
-
49
40
  end
50
41
 
51
42
  end
@@ -0,0 +1,121 @@
1
+ require 'spec_helper'
2
+
3
+ module Alchemy
4
+ describe Admin::DashboardController do
5
+
6
+ before do
7
+ sign_in(admin_user)
8
+ end
9
+
10
+ describe '#index' do
11
+ before do
12
+ Page.stub_chain(:from_current_site, :all_last_edited_from).and_return([])
13
+ Page.stub_chain(:from_current_site, :all_locked).and_return([])
14
+ User.stub!(:logged_in).and_return([controller.current_user])
15
+ controller.current_user.stub!(:sign_in_count).and_return(5)
16
+ end
17
+
18
+ it "should assign @last_edited_pages" do
19
+ get :index
20
+ expect(assigns(:last_edited_pages)).to eq([])
21
+ end
22
+
23
+ it "should assign @locked_pages" do
24
+ get :index
25
+ expect(assigns(:locked_pages)).to eq([])
26
+ end
27
+
28
+ it "should assign @online_users" do
29
+ get :index
30
+ expect(assigns(:online_users)).to eq([])
31
+ end
32
+
33
+ it "should assign @first_time" do
34
+ get :index
35
+ expect(assigns(:first_time)).to eq(false)
36
+ end
37
+
38
+ it "should assign @sites" do
39
+ get :index
40
+ expect(assigns(:sites)).to eq(Site.scoped)
41
+ end
42
+ end
43
+
44
+ describe '#info' do
45
+ it "should assign @alchemy_version with the current Alchemy version" do
46
+ get :info
47
+ expect(assigns(:alchemy_version)).to eq(Alchemy.version)
48
+ end
49
+ end
50
+
51
+ describe '#update_check' do
52
+
53
+ context "if current Alchemy version equals the latest released version or it is newer" do
54
+ before do
55
+ controller.stub!(:latest_alchemy_version).and_return('2.6')
56
+ Alchemy.stub!(:version).and_return("2.6")
57
+ end
58
+
59
+ it "should render 'false'" do
60
+ get :update_check
61
+ expect(response.body).to eq('false')
62
+ end
63
+ end
64
+
65
+ context "if current Alchemy version is older than latest released version" do
66
+ before do
67
+ controller.stub!(:latest_alchemy_version).and_return('2.6')
68
+ Alchemy.stub!(:version).and_return("2.5")
69
+ end
70
+
71
+ it "should render 'true'" do
72
+ get :update_check
73
+ expect(response.body).to eq('true')
74
+ end
75
+ end
76
+
77
+ context "requesting rubygems.org" do
78
+ before do
79
+ Net::HTTP.any_instance.stub(:request).and_return(
80
+ OpenStruct.new({code: '200', body: '[{"number": "2.6"}, {"number": "2.5"}]'})
81
+ )
82
+ Alchemy.stub!(:version).and_return("2.6")
83
+ end
84
+
85
+ it "should have response code of 200" do
86
+ get :update_check
87
+ expect(response.code).to eq('200')
88
+ end
89
+ end
90
+
91
+ context "requesting github.com" do
92
+ before do
93
+ controller.stub!(:query_rubygems).and_return(OpenStruct.new({code: '503'}))
94
+ Net::HTTP.any_instance.stub(:request).and_return(
95
+ OpenStruct.new({code: '200', body: '[{"name": "2.6"}, {"name": "2.5"}]'})
96
+ )
97
+ end
98
+
99
+ it "should have response code of 200" do
100
+ get :update_check
101
+ expect(response.code).to eq('200')
102
+ end
103
+ end
104
+
105
+ context "rubygems.org and github.com are unavailable" do
106
+ before do
107
+ Net::HTTP.any_instance.stub(:request).and_return(
108
+ OpenStruct.new({code: '503'})
109
+ )
110
+ end
111
+
112
+ it "should have status code 503" do
113
+ get :update_check
114
+ expect(response.code).to eq('503')
115
+ end
116
+ end
117
+
118
+ end
119
+
120
+ end
121
+ end
@@ -4,7 +4,7 @@ module Alchemy
4
4
  describe Admin::ElementsController do
5
5
 
6
6
  before(:each) do
7
- sign_in :user, FactoryGirl.create(:admin_user)
7
+ sign_in(admin_user)
8
8
  end
9
9
 
10
10
  let(:alchemy_page) { FactoryGirl.create(:page, :urlname => 'lulu') }
@@ -0,0 +1,67 @@
1
+ require "spec_helper"
2
+
3
+ module Alchemy
4
+ describe Admin::EssenceFilesController do
5
+
6
+ before do
7
+ sign_in(admin_user)
8
+ end
9
+
10
+ let(:content) { mock_model('Content', essence: essence_file) }
11
+ let(:essence_file) { mock_model('EssenceFile', :attachment= => nil) }
12
+ let(:attachment) { mock_model('Attachment') }
13
+
14
+ describe '#edit' do
15
+ before do
16
+ Content.stub!(:find).with(content.id.to_s).and_return(content)
17
+ end
18
+
19
+ it "should assign @content with the Content found by id" do
20
+ get :edit, id: content.id
21
+ expect(assigns(:content)).to eq(content)
22
+ end
23
+
24
+ it "should assign @essence_file with content's essence" do
25
+ get :edit, id: content.id
26
+ expect(assigns(:essence_file)).to eq(content.essence)
27
+ end
28
+
29
+ context 'xhr request' do
30
+ it "should not render a layout" do
31
+ xhr :get, :edit, id: content.id
32
+ expect(@layouts).to be_empty
33
+ end
34
+ end
35
+ end
36
+
37
+ describe '#update' do
38
+ before do
39
+ EssenceFile.stub!(:find).with(essence_file.id.to_s).and_return(essence_file)
40
+ end
41
+
42
+ it "should update the attributes of essence_file" do
43
+ essence_file.should_receive(:update_attributes).and_return(true)
44
+ xhr :put, :update, id: essence_file.id
45
+ end
46
+ end
47
+
48
+ describe '#assign' do
49
+ before do
50
+ Content.stub!(:find_by_id).with(content.id.to_s).and_return(content)
51
+ Attachment.stub!(:find_by_id).and_return(attachment)
52
+ end
53
+
54
+ it "should assign @attachment with the Attachment found by attachment_id" do
55
+ xhr :put, :assign, id: content.id, attachment_id: attachment.id
56
+ expect(assigns(:attachment)).to eq(attachment)
57
+ end
58
+
59
+ it "should assign @content.essence.attachment with the attachment found by id" do
60
+ content.essence.should_receive(:attachment=).with(attachment)
61
+ xhr :put, :assign, id: content.id, attachment_id: attachment.id
62
+ end
63
+
64
+ end
65
+
66
+ end
67
+ end
@@ -0,0 +1,161 @@
1
+ require 'spec_helper'
2
+
3
+ module Alchemy
4
+ describe Admin::EssencePicturesController do
5
+ before { sign_in(admin_user) }
6
+
7
+ let(:essence) { EssencePicture.new }
8
+ let(:content) { Content.new }
9
+ let(:picture) { Picture.new }
10
+
11
+ describe '#edit' do
12
+ before do
13
+ EssencePicture.should_receive(:find).and_return(essence)
14
+ Content.should_receive(:find).and_return(content)
15
+ end
16
+
17
+ it 'should assign @essence_picture and @content instance variables' do
18
+ post :edit, id: 1, content_id: 1
19
+ expect(assigns(:essence_picture)).to be_a(EssencePicture)
20
+ expect(assigns(:content)).to be_a(Content)
21
+ end
22
+ end
23
+
24
+ describe '#crop' do
25
+ before do
26
+ EssencePicture.should_receive(:find).and_return(essence)
27
+ end
28
+
29
+ context 'with no picture assigned' do
30
+ before { essence.should_receive(:picture).and_return(nil) }
31
+
32
+ it "renders error message" do
33
+ get :crop, id: 1
34
+ expect(assigns(:no_image_notice)).to eq(Alchemy::I18n.t(:no_image_for_cropper_found))
35
+ end
36
+ end
37
+
38
+ context 'with picture assigned' do
39
+ let(:default_mask) { {'x1' => '0', 'y1' => '0', 'x2' => '100', 'y2' => '100'} }
40
+
41
+ before do
42
+ picture.image_file_width = 300
43
+ picture.image_file_height = 250
44
+ essence.should_receive(:picture).and_return(picture)
45
+ end
46
+
47
+ context 'with no render_size present in essence' do
48
+ before do
49
+ essence.should_receive(:render_size).and_return(nil)
50
+ end
51
+
52
+ context 'with sizes in params' do
53
+ it "sets sizes to given values" do
54
+ get :crop, id: 1, options: {image_size: '300x250'}
55
+ expect(assigns(:size_x)).to eq('300')
56
+ expect(assigns(:size_y)).to eq('250')
57
+ end
58
+ end
59
+
60
+ context 'with no sizes in params' do
61
+ it "sets sizes to zero" do
62
+ get :crop, id: 1
63
+ expect(assigns(:size_x)).to eq(0)
64
+ expect(assigns(:size_y)).to eq(0)
65
+ end
66
+ end
67
+ end
68
+
69
+ context 'with render_size present in essence' do
70
+ before do
71
+ essence.stub(:render_size).and_return('30x25')
72
+ end
73
+
74
+ it "sets sizes from these values" do
75
+ get :crop, id: 1
76
+ expect(assigns(:size_x)).to eq('30')
77
+ expect(assigns(:size_y)).to eq('25')
78
+ end
79
+ end
80
+
81
+ context 'no crop sizes present in essence' do
82
+ before do
83
+ essence.stub(:crop_from).and_return(nil)
84
+ essence.stub(:crop_size).and_return(nil)
85
+ picture.should_receive(:default_mask).and_return(default_mask)
86
+ end
87
+
88
+ it "assigns default mask boxes" do
89
+ get :crop, id: 1
90
+ expect(assigns(:initial_box)).to eq(default_mask)
91
+ expect(assigns(:default_box)).to eq(default_mask)
92
+ end
93
+ end
94
+
95
+ context 'crop sizes present in essence' do
96
+ let(:mask) { {'x1' => '0', 'y1' => '0', 'x2' => '120', 'y2' => '160'} }
97
+
98
+ before do
99
+ essence.stub(:crop_from).and_return('0x0')
100
+ essence.stub(:crop_size).and_return('120x160')
101
+ picture.should_receive(:default_mask).and_return(default_mask)
102
+ end
103
+
104
+ it "assigns cropping boxes" do
105
+ essence.should_receive(:cropping_mask).and_return(mask)
106
+ get :crop, id: 1
107
+ expect(assigns(:initial_box)).to eq(mask)
108
+ expect(assigns(:default_box)).to eq(default_mask)
109
+ end
110
+ end
111
+
112
+ context 'with fixed_ratio set to false' do
113
+ it "sets ratio to false" do
114
+ get :crop, id: 1, options: {fixed_ratio: false}
115
+ expect(assigns(:ratio)).to eq(false)
116
+ end
117
+ end
118
+
119
+ context 'with no fixed_ratio set in params' do
120
+ it "sets a fixed ratio from sizes" do
121
+ get :crop, id: 1, options: {image_size: '80x60'}
122
+ expect(assigns(:ratio)).to eq(80.0/60.0)
123
+ end
124
+ end
125
+
126
+ context 'with size_y set to zero' do
127
+ it "sets ratio to 1" do
128
+ get :crop, id: 1
129
+ expect(assigns(:ratio)).to eq(1)
130
+ end
131
+ end
132
+ end
133
+ end
134
+
135
+ describe '#update' do
136
+ before do
137
+ EssencePicture.should_receive(:find).and_return(essence)
138
+ Content.should_receive(:find).and_return(content)
139
+ end
140
+
141
+ it "updates the essence attributes" do
142
+ essence.should_receive(:update_attributes).and_return(true)
143
+ xhr :put, :update, id: 1, essence_picture: {render_size: '1x1'}
144
+ end
145
+ end
146
+
147
+ describe '#assign' do
148
+ before do
149
+ Content.should_receive(:find).and_return(content)
150
+ Content.any_instance.stub(:essence).and_return(essence)
151
+ Picture.should_receive(:find_by_id).and_return(picture)
152
+ end
153
+
154
+ it "should assign a Picture" do
155
+ xhr :put, :assign, content_id: '1', picture_id: '1'
156
+ expect(assigns(:content).essence.picture).to eq(picture)
157
+ end
158
+ end
159
+
160
+ end
161
+ end
@@ -6,7 +6,7 @@ end
6
6
  describe Alchemy::Admin::LanguagesController do
7
7
 
8
8
  before do
9
- sign_in :user, FactoryGirl.create(:admin_user)
9
+ sign_in(admin_user)
10
10
  end
11
11
 
12
12
  describe "new" do