alchemy_cms 2.8.3 → 2.9.0

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 (152) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +3 -2
  3. data/README.md +108 -25
  4. data/alchemy_cms.gemspec +0 -1
  5. data/app/assets/stylesheets/alchemy/archive.scss +2 -2
  6. data/app/assets/stylesheets/alchemy/base.scss +0 -37
  7. data/app/assets/stylesheets/alchemy/elements.scss +1 -1
  8. data/app/assets/stylesheets/alchemy/flash.scss +1 -1
  9. data/app/assets/stylesheets/alchemy/form_elements.scss +1 -1
  10. data/app/assets/stylesheets/alchemy/icon-font.css.scss +40 -40
  11. data/app/assets/stylesheets/alchemy/icons.scss +4 -32
  12. data/app/assets/stylesheets/alchemy/jquery-ui.scss +4 -4
  13. data/app/assets/stylesheets/alchemy/menubar.css.scss +20 -12
  14. data/app/assets/stylesheets/alchemy/modules.scss +0 -4
  15. data/app/assets/stylesheets/alchemy/search.scss +1 -1
  16. data/app/assets/stylesheets/alchemy/sitemap.scss +1 -1
  17. data/app/assets/stylesheets/tiny_mce/plugins/inlinepopups/skins/alchemy-tinymce-dialog/window.css.scss +3 -3
  18. data/app/controllers/alchemy/admin/base_controller.rb +12 -8
  19. data/app/controllers/alchemy/admin/dashboard_controller.rb +10 -5
  20. data/app/controllers/alchemy/admin/elements_controller.rb +1 -1
  21. data/app/controllers/alchemy/admin/essence_pictures_controller.rb +8 -1
  22. data/app/controllers/alchemy/admin/layoutpages_controller.rb +1 -1
  23. data/app/controllers/alchemy/admin/pages_controller.rb +11 -6
  24. data/app/controllers/alchemy/admin/resources_controller.rb +2 -2
  25. data/app/controllers/alchemy/admin/users_controller.rb +1 -1
  26. data/app/controllers/alchemy/base_controller.rb +71 -37
  27. data/app/controllers/alchemy/elements_controller.rb +1 -1
  28. data/app/controllers/alchemy/pages_controller.rb +9 -3
  29. data/app/controllers/alchemy/pictures_controller.rb +1 -0
  30. data/app/helpers/alchemy/admin/base_helper.rb +2 -10
  31. data/app/helpers/alchemy/admin/pages_helper.rb +1 -1
  32. data/app/helpers/alchemy/base_helper.rb +1 -1
  33. data/app/helpers/alchemy/pages_helper.rb +1 -1
  34. data/app/models/alchemy/attachment.rb +3 -4
  35. data/app/models/alchemy/cell.rb +1 -1
  36. data/app/models/alchemy/content.rb +3 -4
  37. data/app/models/alchemy/element.rb +5 -6
  38. data/app/models/alchemy/folded_page.rb +1 -1
  39. data/app/models/alchemy/language.rb +1 -1
  40. data/app/models/alchemy/message.rb +1 -7
  41. data/app/models/alchemy/page.rb +12 -10
  42. data/app/models/alchemy/page/{cells.rb → page_cells.rb} +2 -2
  43. data/app/models/alchemy/page/{elements.rb → page_elements.rb} +2 -2
  44. data/app/models/alchemy/page/{naming.rb → page_naming.rb} +1 -1
  45. data/app/models/alchemy/page/{natures.rb → page_natures.rb} +3 -3
  46. data/app/models/alchemy/page/{scopes.rb → page_scopes.rb} +3 -3
  47. data/app/models/alchemy/page/page_users.rb +33 -0
  48. data/app/models/alchemy/picture.rb +3 -3
  49. data/app/models/alchemy/site.rb +2 -2
  50. data/app/views/alchemy/admin/dashboard/_locked_pages.html.erb +1 -1
  51. data/app/views/alchemy/admin/dashboard/_recent_pages.html.erb +1 -1
  52. data/app/views/alchemy/admin/dashboard/_sites.html.erb +1 -1
  53. data/app/views/alchemy/admin/dashboard/index.html.erb +10 -4
  54. data/app/views/alchemy/admin/pages/_page.html.erb +1 -1
  55. data/app/views/alchemy/admin/pages/update.js.erb +1 -1
  56. data/app/views/alchemy/{user_sessions → base}/leave.html.erb +2 -2
  57. data/app/views/alchemy/base/permission_denied.js.erb +3 -2
  58. data/app/views/layouts/alchemy/admin.html.erb +6 -3
  59. data/config/alchemy/config.yml +1 -11
  60. data/config/alchemy/modules.yml +0 -12
  61. data/config/locales/alchemy.de.yml +3 -40
  62. data/config/locales/alchemy.en.yml +2 -22
  63. data/config/routes.rb +2 -27
  64. data/db/migrate/20130827094554_alchemy_two_point_six.rb +0 -31
  65. data/lib/alchemy/auth_accessors.rb +54 -0
  66. data/lib/alchemy/capistrano.rb +5 -17
  67. data/lib/alchemy/engine.rb +7 -7
  68. data/lib/alchemy/errors.rb +6 -0
  69. data/lib/alchemy/essence.rb +2 -2
  70. data/lib/alchemy/seeder.rb +1 -1
  71. data/lib/alchemy/tasks/helpers.rb +83 -0
  72. data/lib/alchemy/test_support/auth_helpers.rb +35 -0
  73. data/lib/alchemy/test_support/controller_requests.rb +37 -0
  74. data/{spec/support → lib/alchemy/test_support}/factories.rb +7 -28
  75. data/{spec/support/alchemy → lib/alchemy/test_support}/integration_helpers.rb +9 -36
  76. data/lib/alchemy/upgrader.rb +8 -7
  77. data/lib/alchemy/upgrader/two_point_nine.rb +33 -0
  78. data/lib/alchemy/userstamp.rb +10 -0
  79. data/lib/alchemy/version.rb +1 -3
  80. data/lib/rails/templates/alchemy.rb +1 -0
  81. data/lib/tasks/alchemy/db.rake +5 -5
  82. data/spec/controllers/admin/attachments_controller_spec.rb +3 -3
  83. data/spec/controllers/admin/dashboard_controller_spec.rb +55 -34
  84. data/spec/controllers/admin/elements_controller_spec.rb +1 -1
  85. data/spec/controllers/admin/essence_pictures_controller_spec.rb +22 -6
  86. data/spec/controllers/admin/pages_controller_spec.rb +41 -58
  87. data/spec/controllers/admin/resources_controller_spec.rb +30 -5
  88. data/spec/controllers/admin/trash_controller_spec.rb +1 -1
  89. data/spec/controllers/attachments_controller_spec.rb +26 -44
  90. data/spec/controllers/base_controller_spec.rb +8 -33
  91. data/spec/controllers/elements_controller_spec.rb +1 -1
  92. data/spec/controllers/pages_controller_spec.rb +7 -15
  93. data/spec/controllers/pictures_controller_spec.rb +44 -5
  94. data/spec/dummy/app/controllers/application_controller.rb +9 -1
  95. data/spec/dummy/app/models/user.rb +14 -0
  96. data/spec/dummy/db/migrate/20130827094554_alchemy_two_point_six.rb +0 -31
  97. data/spec/dummy/db/schema.rb +0 -31
  98. data/spec/features/admin/language_tree_feature_spec.rb +34 -0
  99. data/spec/features/admin/pages_controller_spec.rb +1 -1
  100. data/spec/features/pages_controller_spec.rb +5 -12
  101. data/spec/features/picture_security_spec.rb +2 -2
  102. data/spec/features/security_spec.rb +6 -45
  103. data/spec/features/translation_integration_spec.rb +11 -20
  104. data/spec/{support → fixtures}/80x60.png +0 -0
  105. data/spec/support/image with spaces.png b/data/spec/fixtures/image with → spaces.png +0 -0
  106. data/spec/{support → fixtures}/image.png +0 -0
  107. data/spec/{support → fixtures}/image2.PNG +0 -0
  108. data/spec/{support → fixtures}/image3.jpeg +0 -0
  109. data/spec/helpers/admin/base_helper_spec.rb +31 -43
  110. data/spec/helpers/admin/pages_helper_spec.rb +4 -2
  111. data/spec/helpers/base_helper_spec.rb +10 -3
  112. data/spec/helpers/pages_helper_spec.rb +32 -22
  113. data/spec/models/attachment_spec.rb +1 -1
  114. data/spec/models/element_spec.rb +33 -57
  115. data/spec/models/message_spec.rb +0 -16
  116. data/spec/models/page_spec.rb +62 -26
  117. data/spec/models/picture_spec.rb +5 -5
  118. data/spec/spec_helper.rb +13 -4
  119. data/spec/tasks/helpers_spec.rb +213 -0
  120. metadata +33 -75
  121. data/app/controllers/alchemy/passwords_controller.rb +0 -35
  122. data/app/controllers/alchemy/user_sessions_controller.rb +0 -67
  123. data/app/controllers/alchemy/users_controller.rb +0 -46
  124. data/app/mailers/alchemy/notifications.rb +0 -33
  125. data/app/models/alchemy/page/users.rb +0 -25
  126. data/app/models/alchemy/user.rb +0 -183
  127. data/app/views/alchemy/admin/users/_table.html.erb +0 -69
  128. data/app/views/alchemy/admin/users/_user.html.erb +0 -39
  129. data/app/views/alchemy/admin/users/edit.html.erb +0 -6
  130. data/app/views/alchemy/admin/users/index.html.erb +0 -58
  131. data/app/views/alchemy/admin/users/new.html.erb +0 -6
  132. data/app/views/alchemy/notifications/admin_user_created.de.text.erb +0 -15
  133. data/app/views/alchemy/notifications/admin_user_created.en.text.erb +0 -15
  134. data/app/views/alchemy/notifications/registered_user_created.de.text.erb +0 -13
  135. data/app/views/alchemy/notifications/registered_user_created.en.text.erb +0 -13
  136. data/app/views/alchemy/notifications/reset_password_instructions.de.text.erb +0 -8
  137. data/app/views/alchemy/notifications/reset_password_instructions.en.text.erb +0 -8
  138. data/app/views/alchemy/passwords/edit.html.erb +0 -35
  139. data/app/views/alchemy/passwords/new.html.erb +0 -30
  140. data/app/views/alchemy/user_sessions/new.html.erb +0 -48
  141. data/app/views/alchemy/users/new.html.erb +0 -14
  142. data/config/initializers/devise.rb +0 -242
  143. data/config/locales/devise.de.yml +0 -58
  144. data/config/locales/devise.en.yml +0 -60
  145. data/lib/rails/generators/alchemy/devise/devise_generator.rb +0 -29
  146. data/spec/controllers/admin/users_controller_spec.rb +0 -132
  147. data/spec/controllers/passwords_controller_spec.rb +0 -16
  148. data/spec/controllers/user_sessions_controller_spec.rb +0 -22
  149. data/spec/controllers/users_controller_spec.rb +0 -66
  150. data/spec/mailers/notifications_spec.rb +0 -67
  151. data/spec/models/user_spec.rb +0 -252
  152. data/spec/support/alchemy/controller_helpers.rb +0 -35
@@ -5,13 +5,14 @@ module Alchemy
5
5
 
6
6
  Dir["#{File.dirname(__FILE__)}/upgrader/*.rb"].each { |f| require f }
7
7
 
8
- extend TwoPointSix
9
- extend TwoPointFive
10
- extend TwoPointFour
11
- extend TwoPointThree
12
- extend TwoPointTwo
13
- extend TwoPointOne
14
- extend TwoPointZero
8
+ extend Alchemy::Upgrader::TwoPointNine
9
+ extend Alchemy::Upgrader::TwoPointSix
10
+ extend Alchemy::Upgrader::TwoPointFive
11
+ extend Alchemy::Upgrader::TwoPointFour
12
+ extend Alchemy::Upgrader::TwoPointThree
13
+ extend Alchemy::Upgrader::TwoPointTwo
14
+ extend Alchemy::Upgrader::TwoPointOne
15
+ extend Alchemy::Upgrader::TwoPointZero
15
16
 
16
17
  class << self
17
18
 
@@ -0,0 +1,33 @@
1
+ module Alchemy
2
+ module Upgrader::TwoPointNine
3
+
4
+ private
5
+
6
+ def alchemy_29_todos
7
+ notice = <<-NOTE
8
+
9
+ Alchemy User Class Removed
10
+ --------------------------
11
+
12
+ We removed the user model from the Alchemy core!
13
+
14
+ You have to provide your own user model or
15
+ add the `alchemy-devise` gem to your Gemfile.
16
+
17
+ If you want to use the default user class from Alchemy:
18
+
19
+ # Gemfile
20
+ gem 'alchemy-devise', '~> 1.1'
21
+
22
+ $ bin/rake alchemy_devise:install:migrations db:migrate
23
+
24
+ In order to add your own user class to Alchemy, please
25
+ make shure it meets the API:
26
+
27
+ https://github.com/magiclabs/alchemy_cms/blob/2.9-stable/lib/alchemy/auth_accessors.rb
28
+
29
+ NOTE
30
+ todo notice
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,10 @@
1
+ # Adds the model stamper ability to the provided user class
2
+ #
3
+ # It only adds it, if the user model is a active_record model.
4
+ #
5
+ if Alchemy.user_class < ActiveRecord::Base
6
+ Alchemy.user_class.class_eval do
7
+ model_stamper
8
+ stampable stamper_class_name: Alchemy.user_class_name
9
+ end
10
+ end
@@ -1,9 +1,7 @@
1
1
  module Alchemy
2
-
3
- VERSION = "2.8.3"
2
+ VERSION = "2.9.0"
4
3
 
5
4
  def self.version
6
5
  VERSION
7
6
  end
8
-
9
7
  end
@@ -2,6 +2,7 @@
2
2
  require File.expand_path('../../../alchemy/version', __FILE__)
3
3
 
4
4
  gem 'alchemy_cms', "~> #{Alchemy::VERSION}"
5
+ gem 'alchemy-devise', github: 'magiclabs/alchemy-devise', branch: '1.1-stable'
5
6
 
6
7
  if yes?("\nDo you want to use Capistrano for deployment? (y/N)")
7
8
  gem 'capistrano', group: 'development'
@@ -1,4 +1,6 @@
1
1
  require 'alchemy/seeder'
2
+ require 'alchemy/tasks/helpers'
3
+ include Alchemy::Tasks::Helpers
2
4
 
3
5
  namespace :alchemy do
4
6
  namespace :db do
@@ -8,13 +10,11 @@ namespace :alchemy do
8
10
  Alchemy::Seeder.seed!
9
11
  end
10
12
 
11
- desc "Dumps the database to STDOUT (Pass DUMP_FILENAME to store the dump into a file). NOTE: This only works with MySQL yet."
13
+ desc "Dumps the database to STDOUT (Pass DUMP_FILENAME to store the dump into a file)."
12
14
  task :dump => :environment do
13
- db_conf = Rails.configuration.database_configuration.fetch(Rails.env)
14
- raise "Sorry, but Alchemy only supports MySQL database dumping at the moment." unless db_conf['adapter'] =~ /mysql/
15
15
  dump_store = ENV['DUMP_FILENAME'] ? " > #{ENV['DUMP_FILENAME']}" : ""
16
- cmd = "mysqldump --user='#{db_conf['username']}'#{db_conf['password'].present? ? " --password='#{db_conf['password']}'" : nil} #{db_conf['database']}#{dump_store}"
17
- system cmd
16
+ dump_cmd = database_dump_command(database_config['adapter'])
17
+ system "#{dump_cmd}#{dump_store}"
18
18
  end
19
19
 
20
20
  end
@@ -8,7 +8,7 @@ module Alchemy
8
8
  before do
9
9
  sign_in(admin_user)
10
10
  end
11
-
11
+
12
12
  describe "#index" do
13
13
 
14
14
  it "should always paginate the records" do
@@ -44,9 +44,9 @@ module Alchemy
44
44
  end
45
45
 
46
46
  end
47
-
47
+
48
48
  describe "#new" do
49
-
49
+
50
50
  context "in overlay" do
51
51
 
52
52
  before do
@@ -2,59 +2,81 @@ require 'spec_helper'
2
2
 
3
3
  module Alchemy
4
4
  describe Admin::DashboardController do
5
+ let(:user) { admin_user }
5
6
 
6
- before do
7
- sign_in(admin_user)
8
- end
7
+ before { sign_in(user) }
9
8
 
10
9
  describe '#index' do
11
10
  before do
12
11
  Page.stub_chain(:from_current_site, :all_last_edited_from).and_return([])
13
12
  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)
13
+ User.stub(:logged_in).and_return([user])
14
+ user.stub(:sign_in_count).and_return(5)
16
15
  end
17
16
 
18
- it "should assign @last_edited_pages" do
17
+ it "assigns @last_edited_pages" do
19
18
  get :index
20
19
  expect(assigns(:last_edited_pages)).to eq([])
21
20
  end
22
21
 
23
- it "should assign @locked_pages" do
22
+ it "assigns @locked_pages" do
24
23
  get :index
25
24
  expect(assigns(:locked_pages)).to eq([])
26
25
  end
27
26
 
28
- it "should assign @online_users" do
29
- get :index
30
- expect(assigns(:online_users)).to eq([])
27
+ context 'with user class having logged_in scope' do
28
+ context 'with other users online' do
29
+ let(:another_user) { mock_model('User') }
30
+
31
+ before do
32
+ Alchemy.user_class.should_receive(:logged_in).and_return([another_user])
33
+ end
34
+
35
+ it "assigns @online_users" do
36
+ get :index
37
+ expect(assigns(:online_users)).to eq([another_user])
38
+ end
39
+ end
40
+
41
+ context 'without other users online' do
42
+ it "does not assign @online_users" do
43
+ get :index
44
+ expect(assigns(:online_users)).to eq([])
45
+ end
46
+ end
31
47
  end
32
48
 
33
- it "should assign @first_time" do
34
- get :index
35
- expect(assigns(:first_time)).to eq(false)
49
+ context 'user having signed in before' do
50
+ before do
51
+ user.should_receive(:sign_in_count).and_return(5)
52
+ user.should_receive(:last_sign_in_at).and_return(Time.now)
53
+ end
54
+
55
+ it "assigns @first_time" do
56
+ get :index
57
+ expect(assigns(:first_time)).to eq(false)
58
+ end
36
59
  end
37
60
 
38
- it "should assign @sites" do
61
+ it "assigns @sites" do
39
62
  get :index
40
63
  expect(assigns(:sites)).to eq(Site.scoped)
41
64
  end
42
65
  end
43
-
66
+
44
67
  describe '#info' do
45
- it "should assign @alchemy_version with the current Alchemy version" do
68
+ it "assigns @alchemy_version with the current Alchemy version" do
46
69
  get :info
47
70
  expect(assigns(:alchemy_version)).to eq(Alchemy.version)
48
71
  end
49
72
  end
50
73
 
51
74
  describe '#update_check' do
52
-
53
75
  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
76
+ before {
77
+ controller.stub(:latest_alchemy_version).and_return('2.6')
78
+ Alchemy.stub(:version).and_return("2.6")
79
+ }
58
80
 
59
81
  it "should render 'false'" do
60
82
  get :update_check
@@ -63,10 +85,10 @@ module Alchemy
63
85
  end
64
86
 
65
87
  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
88
+ before {
89
+ controller.stub(:latest_alchemy_version).and_return('2.6')
90
+ Alchemy.stub(:version).and_return("2.5")
91
+ }
70
92
 
71
93
  it "should render 'true'" do
72
94
  get :update_check
@@ -75,12 +97,12 @@ module Alchemy
75
97
  end
76
98
 
77
99
  context "requesting rubygems.org" do
78
- before do
100
+ before {
79
101
  Net::HTTP.any_instance.stub(:request).and_return(
80
102
  OpenStruct.new({code: '200', body: '[{"number": "2.6"}, {"number": "2.5"}]'})
81
103
  )
82
- Alchemy.stub!(:version).and_return("2.6")
83
- end
104
+ Alchemy.stub(:version).and_return("2.6")
105
+ }
84
106
 
85
107
  it "should have response code of 200" do
86
108
  get :update_check
@@ -89,12 +111,12 @@ module Alchemy
89
111
  end
90
112
 
91
113
  context "requesting github.com" do
92
- before do
93
- controller.stub!(:query_rubygems).and_return(OpenStruct.new({code: '503'}))
114
+ before {
115
+ controller.stub(:query_rubygems).and_return(OpenStruct.new({code: '503'}))
94
116
  Net::HTTP.any_instance.stub(:request).and_return(
95
117
  OpenStruct.new({code: '200', body: '[{"name": "2.6"}, {"name": "2.5"}]'})
96
118
  )
97
- end
119
+ }
98
120
 
99
121
  it "should have response code of 200" do
100
122
  get :update_check
@@ -103,18 +125,17 @@ module Alchemy
103
125
  end
104
126
 
105
127
  context "rubygems.org and github.com are unavailable" do
106
- before do
128
+ before {
107
129
  Net::HTTP.any_instance.stub(:request).and_return(
108
130
  OpenStruct.new({code: '503'})
109
131
  )
110
- end
132
+ }
111
133
 
112
134
  it "should have status code 503" do
113
135
  get :update_check
114
136
  expect(response.code).to eq('503')
115
137
  end
116
138
  end
117
-
118
139
  end
119
140
 
120
141
  end
@@ -111,7 +111,7 @@ module Alchemy
111
111
  before(:each) do
112
112
  @element = FactoryGirl.create(:element, :public => false, :position => nil, :page_id => 58, :cell_id => 32)
113
113
  # Because of a before_create filter it can not be created with a nil position and needs to be trashed here
114
- @element.trash
114
+ @element.trash!
115
115
  end
116
116
 
117
117
  it "should set a new position to the element" do
@@ -41,7 +41,7 @@ module Alchemy
41
41
  before do
42
42
  picture.image_file_width = 300
43
43
  picture.image_file_height = 250
44
- essence.should_receive(:picture).and_return(picture)
44
+ essence.should_receive(:picture).any_number_of_times.and_return(picture)
45
45
  end
46
46
 
47
47
  context 'with no render_size present in essence' do
@@ -67,14 +67,30 @@ module Alchemy
67
67
  end
68
68
 
69
69
  context 'with render_size present in essence' do
70
- before do
70
+ it "sets sizes from these values" do
71
71
  essence.stub(:render_size).and_return('30x25')
72
- end
73
72
 
74
- it "sets sizes from these values" do
75
73
  get :crop, id: 1
76
- expect(assigns(:size_x)).to eq('30')
77
- expect(assigns(:size_y)).to eq('25')
74
+ expect(assigns(:size_x)).to eq(30)
75
+ expect(assigns(:size_y)).to eq(25)
76
+ end
77
+
78
+ context 'when width or height is not fixed' do
79
+ it 'infers the height from the image file preserving the aspect ratio' do
80
+ essence.stub(:render_size).and_return('30')
81
+
82
+ get :crop, id: 1
83
+ expect(assigns(:size_x)).to eq(30)
84
+ expect(assigns(:size_y)).to eq(25)
85
+ end
86
+
87
+ it 'infers the height from the image file preserving the aspect ratio' do
88
+ essence.stub(:render_size).and_return('x25')
89
+
90
+ get :crop, id: 1
91
+ expect(assigns(:size_x)).to eq(30)
92
+ expect(assigns(:size_y)).to eq(25)
93
+ end
78
94
  end
79
95
  end
80
96
 
@@ -3,9 +3,17 @@ require 'spec_helper'
3
3
 
4
4
  module Alchemy
5
5
  describe Admin::PagesController do
6
+ let(:user) { editor_user }
7
+ before { sign_in(user) }
6
8
 
7
- before do
8
- sign_in(admin_user)
9
+ describe '#index' do
10
+ let(:language_root) { FactoryGirl.build_stubbed(:language_root_page) }
11
+
12
+ it "assigns @page_root variable" do
13
+ Page.should_receive(:language_root_for).with(1).and_return(language_root)
14
+ get :index
15
+ assigns(:page_root).should be(language_root)
16
+ end
9
17
  end
10
18
 
11
19
  describe "#flush" do
@@ -21,11 +29,9 @@ module Alchemy
21
29
  context "pages in clipboard" do
22
30
 
23
31
  let(:clipboard) { session[:clipboard] = Clipboard.new }
24
- let(:page) { mock_model('Page', name: 'Foobar') }
32
+ let(:page) { mock_model(Alchemy::Page, name: 'Foobar') }
25
33
 
26
- before do
27
- clipboard[:pages] = [{id: page.id, action: 'copy'}]
28
- end
34
+ before { clipboard[:pages] = [{id: page.id, action: 'copy'}] }
29
35
 
30
36
  it "should load all pages from clipboard" do
31
37
  get :new, {page_id: page.id, format: :js}
@@ -36,21 +42,20 @@ module Alchemy
36
42
  end
37
43
 
38
44
  describe '#show' do
39
-
40
- let(:page) { mock_model('Page', language_code: 'nl') }
45
+ let(:page) { mock_model(Alchemy::Page, language_code: 'nl') }
41
46
 
42
47
  before do
43
- Page.stub!(:find).with("#{page.id}").and_return(page)
44
- Page.stub!(:language_root_for).and_return(mock_model('Page'))
48
+ Page.should_receive(:find).with("#{page.id}").and_return(page)
49
+ Page.stub(:language_root_for).and_return(mock_model(Alchemy::Page))
45
50
  end
46
51
 
47
52
  it "should assign @preview_mode with true" do
48
- post :show, id: page.id
53
+ get :show, id: page.id
49
54
  expect(assigns(:preview_mode)).to eq(true)
50
55
  end
51
56
 
52
57
  it "should set the I18n locale to the pages language code" do
53
- post :show, id: page.id
58
+ get :show, id: page.id
54
59
  expect(::I18n.locale).to eq(:nl)
55
60
  end
56
61
  end
@@ -151,7 +156,7 @@ module Alchemy
151
156
  let(:page) { mock_model(Page, {name: 'Foobar', slug: 'foobar', urlname: 'root/parent/foobar', redirects_to_external?: false, layoutpage?: false, taggable?: false}) }
152
157
 
153
158
  it "should always show the slug" do
154
- Page.stub!(:find).and_return(page)
159
+ Page.stub(:find).and_return(page)
155
160
  get :configure, {id: page.id, format: :js}
156
161
  response.body.should match /value="foobar"/
157
162
  end
@@ -160,30 +165,21 @@ module Alchemy
160
165
 
161
166
  describe '#create' do
162
167
  let(:language) { mock_model('Language', code: 'kl') }
163
- let(:parent) { mock_model('Page', language: language) }
164
- let(:page_params) do
165
- {parent_id: parent.id, name: 'new Page'}
166
- end
168
+ let(:parent) { mock_model(Alchemy::Page, language: language) }
169
+ let(:page_params) { {parent_id: parent.id, name: 'new Page'} }
167
170
 
168
- context "" do
171
+ context "a new page" do
169
172
  before do
170
173
  Page.any_instance.stub(:set_language_from_parent_or_default_language)
171
- Page.any_instance.stub(save: true)
174
+ Page.any_instance.stub(:save).and_return(true)
172
175
  end
173
176
 
174
- it "nests a new page under given parent" do
175
- controller.stub!(:edit_admin_page_path).and_return('bla')
177
+ it "is nested under given parent" do
178
+ controller.stub(:edit_admin_page_path).and_return('bla')
176
179
  post :create, {page: page_params, format: :js}
177
180
  expect(assigns(:page).parent_id).to eq(parent.id)
178
181
  end
179
182
 
180
- it "redirects to edit page template" do
181
- page = mock_model('Page')
182
- controller.should_receive(:edit_admin_page_path).and_return('bla')
183
- post :create, page: page_params
184
- response.should redirect_to('bla')
185
- end
186
-
187
183
  context "if new page can not be saved" do
188
184
  it "should redirect to admin_pages_path" do
189
185
  Page.any_instance.stub(:save).and_return(false)
@@ -198,14 +194,14 @@ module Alchemy
198
194
  end
199
195
 
200
196
  it "should redirect to given url" do
201
- post :create, page: page_params, redirect_to: admin_users_path
202
- response.should redirect_to(admin_users_path)
197
+ post :create, page: page_params, redirect_to: admin_pictures_path
198
+ response.should redirect_to(admin_pictures_path)
203
199
  end
204
200
 
205
201
  context "but new page can not be saved" do
206
202
  it "should redirect to admin_pages_path" do
207
203
  Page.any_instance.stub(:save).and_return(false)
208
- post :create, page: {}, redirect_to: admin_users_path
204
+ post :create, page: {}, redirect_to: Alchemy.login_path
209
205
  response.should redirect_to(admin_pages_path)
210
206
  end
211
207
  end
@@ -221,7 +217,7 @@ module Alchemy
221
217
  end
222
218
 
223
219
  context "with paste_from_clipboard in parameters" do
224
- let(:page_in_clipboard) { mock_model('Page') }
220
+ let(:page_in_clipboard) { mock_model(Alchemy::Page) }
225
221
 
226
222
  before do
227
223
  Page.stub!(:find_by_id).with(parent.id).and_return(parent)
@@ -279,12 +275,10 @@ module Alchemy
279
275
  let(:clipboard) { session[:clipboard] = Clipboard.new }
280
276
  let(:page) { FactoryGirl.create(:public_page) }
281
277
 
282
- before do
283
- clipboard[:pages] = [{id: page.id}]
284
- end
278
+ before { clipboard[:pages] = [{id: page.id}] }
285
279
 
286
280
  it "should also remove the page from clipboard" do
287
- post :destroy, {id: page.id, _method: :delete}
281
+ post :destroy, {id: page.id, _method: :delete, format: 'js'}
288
282
  clipboard[:pages].should be_empty
289
283
  end
290
284
 
@@ -306,7 +300,7 @@ module Alchemy
306
300
  end
307
301
 
308
302
  describe '#visit' do
309
- let(:page) { mock_model('Page', urlname: 'home') }
303
+ let(:page) { mock_model(Alchemy::Page, urlname: 'home') }
310
304
 
311
305
  before do
312
306
  Page.stub!(:find).with("#{page.id}").and_return(page)
@@ -320,39 +314,30 @@ module Alchemy
320
314
  end
321
315
 
322
316
  describe '#fold' do
323
- let(:page) { mock_model('Page') }
324
-
325
- before do
326
- Page.stub!(:find).with(page.id).and_return(page)
327
- end
317
+ let(:page) { mock_model(Alchemy::Page) }
318
+ before { Page.stub(:find).and_return(page) }
328
319
 
329
320
  context "if page is currently not folded" do
330
- before do
331
- page.stub!(:folded?).and_return(false)
332
- end
321
+ before { page.stub(:folded?).and_return(false) }
333
322
 
334
323
  it "should fold the page" do
335
- page.should_receive(:fold!).with(controller.current_user.id, true).and_return(true)
324
+ page.should_receive(:fold!).with(user.id, true).and_return(true)
336
325
  post :fold, id: page.id, format: :js
337
326
  end
338
327
  end
339
328
 
340
329
  context "if page is already folded" do
341
- before do
342
- page.stub!(:folded?).and_return(true)
343
- end
330
+ before { page.stub(:folded?).and_return(true) }
344
331
 
345
332
  it "should unfold the page" do
346
- page.should_receive(:fold!).with(controller.current_user.id, false).and_return(true)
333
+ page.should_receive(:fold!).with(user.id, false).and_return(true)
347
334
  post :fold, id: page.id, format: :js
348
335
  end
349
336
  end
350
337
  end
351
338
 
352
339
  describe '#sort' do
353
- before do
354
- Page.stub!(:language_root_for).and_return(mock_model('Page'))
355
- end
340
+ before { Page.stub(:language_root_for).and_return(mock_model(Alchemy::Page)) }
356
341
 
357
342
  it "should assign @sorting with true" do
358
343
  get :sort, format: :js
@@ -361,16 +346,15 @@ module Alchemy
361
346
  end
362
347
 
363
348
  describe '#unlock' do
364
- let(:page) { mock_model('Page', name: 'Best practices') }
349
+ let(:page) { mock_model(Alchemy::Page, name: 'Best practices') }
365
350
 
366
351
  before do
367
- page.stub!(:unlock!).and_return(true)
368
- Page.stub!(:find).with("#{page.id}").and_return(page)
352
+ Page.stub(:find).with("#{page.id}").and_return(page)
369
353
  Page.stub_chain(:from_current_site, :all_locked_by).and_return(nil)
354
+ page.should_receive(:unlock!).and_return(true)
370
355
  end
371
356
 
372
357
  it "should unlock the page" do
373
- page.should_receive(:unlock!)
374
358
  post :unlock, id: "#{page.id}", format: :js
375
359
  end
376
360
 
@@ -385,7 +369,6 @@ module Alchemy
385
369
  end
386
370
  end
387
371
  end
388
-
389
372
  end
390
373
 
391
374
  end