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.
- checksums.yaml +4 -4
- data/.travis.yml +3 -2
- data/README.md +108 -25
- data/alchemy_cms.gemspec +0 -1
- data/app/assets/stylesheets/alchemy/archive.scss +2 -2
- data/app/assets/stylesheets/alchemy/base.scss +0 -37
- data/app/assets/stylesheets/alchemy/elements.scss +1 -1
- data/app/assets/stylesheets/alchemy/flash.scss +1 -1
- data/app/assets/stylesheets/alchemy/form_elements.scss +1 -1
- data/app/assets/stylesheets/alchemy/icon-font.css.scss +40 -40
- data/app/assets/stylesheets/alchemy/icons.scss +4 -32
- data/app/assets/stylesheets/alchemy/jquery-ui.scss +4 -4
- data/app/assets/stylesheets/alchemy/menubar.css.scss +20 -12
- data/app/assets/stylesheets/alchemy/modules.scss +0 -4
- data/app/assets/stylesheets/alchemy/search.scss +1 -1
- data/app/assets/stylesheets/alchemy/sitemap.scss +1 -1
- data/app/assets/stylesheets/tiny_mce/plugins/inlinepopups/skins/alchemy-tinymce-dialog/window.css.scss +3 -3
- data/app/controllers/alchemy/admin/base_controller.rb +12 -8
- data/app/controllers/alchemy/admin/dashboard_controller.rb +10 -5
- data/app/controllers/alchemy/admin/elements_controller.rb +1 -1
- data/app/controllers/alchemy/admin/essence_pictures_controller.rb +8 -1
- data/app/controllers/alchemy/admin/layoutpages_controller.rb +1 -1
- data/app/controllers/alchemy/admin/pages_controller.rb +11 -6
- data/app/controllers/alchemy/admin/resources_controller.rb +2 -2
- data/app/controllers/alchemy/admin/users_controller.rb +1 -1
- data/app/controllers/alchemy/base_controller.rb +71 -37
- data/app/controllers/alchemy/elements_controller.rb +1 -1
- data/app/controllers/alchemy/pages_controller.rb +9 -3
- data/app/controllers/alchemy/pictures_controller.rb +1 -0
- data/app/helpers/alchemy/admin/base_helper.rb +2 -10
- data/app/helpers/alchemy/admin/pages_helper.rb +1 -1
- data/app/helpers/alchemy/base_helper.rb +1 -1
- data/app/helpers/alchemy/pages_helper.rb +1 -1
- data/app/models/alchemy/attachment.rb +3 -4
- data/app/models/alchemy/cell.rb +1 -1
- data/app/models/alchemy/content.rb +3 -4
- data/app/models/alchemy/element.rb +5 -6
- data/app/models/alchemy/folded_page.rb +1 -1
- data/app/models/alchemy/language.rb +1 -1
- data/app/models/alchemy/message.rb +1 -7
- data/app/models/alchemy/page.rb +12 -10
- data/app/models/alchemy/page/{cells.rb → page_cells.rb} +2 -2
- data/app/models/alchemy/page/{elements.rb → page_elements.rb} +2 -2
- data/app/models/alchemy/page/{naming.rb → page_naming.rb} +1 -1
- data/app/models/alchemy/page/{natures.rb → page_natures.rb} +3 -3
- data/app/models/alchemy/page/{scopes.rb → page_scopes.rb} +3 -3
- data/app/models/alchemy/page/page_users.rb +33 -0
- data/app/models/alchemy/picture.rb +3 -3
- data/app/models/alchemy/site.rb +2 -2
- data/app/views/alchemy/admin/dashboard/_locked_pages.html.erb +1 -1
- data/app/views/alchemy/admin/dashboard/_recent_pages.html.erb +1 -1
- data/app/views/alchemy/admin/dashboard/_sites.html.erb +1 -1
- data/app/views/alchemy/admin/dashboard/index.html.erb +10 -4
- data/app/views/alchemy/admin/pages/_page.html.erb +1 -1
- data/app/views/alchemy/admin/pages/update.js.erb +1 -1
- data/app/views/alchemy/{user_sessions → base}/leave.html.erb +2 -2
- data/app/views/alchemy/base/permission_denied.js.erb +3 -2
- data/app/views/layouts/alchemy/admin.html.erb +6 -3
- data/config/alchemy/config.yml +1 -11
- data/config/alchemy/modules.yml +0 -12
- data/config/locales/alchemy.de.yml +3 -40
- data/config/locales/alchemy.en.yml +2 -22
- data/config/routes.rb +2 -27
- data/db/migrate/20130827094554_alchemy_two_point_six.rb +0 -31
- data/lib/alchemy/auth_accessors.rb +54 -0
- data/lib/alchemy/capistrano.rb +5 -17
- data/lib/alchemy/engine.rb +7 -7
- data/lib/alchemy/errors.rb +6 -0
- data/lib/alchemy/essence.rb +2 -2
- data/lib/alchemy/seeder.rb +1 -1
- data/lib/alchemy/tasks/helpers.rb +83 -0
- data/lib/alchemy/test_support/auth_helpers.rb +35 -0
- data/lib/alchemy/test_support/controller_requests.rb +37 -0
- data/{spec/support → lib/alchemy/test_support}/factories.rb +7 -28
- data/{spec/support/alchemy → lib/alchemy/test_support}/integration_helpers.rb +9 -36
- data/lib/alchemy/upgrader.rb +8 -7
- data/lib/alchemy/upgrader/two_point_nine.rb +33 -0
- data/lib/alchemy/userstamp.rb +10 -0
- data/lib/alchemy/version.rb +1 -3
- data/lib/rails/templates/alchemy.rb +1 -0
- data/lib/tasks/alchemy/db.rake +5 -5
- data/spec/controllers/admin/attachments_controller_spec.rb +3 -3
- data/spec/controllers/admin/dashboard_controller_spec.rb +55 -34
- data/spec/controllers/admin/elements_controller_spec.rb +1 -1
- data/spec/controllers/admin/essence_pictures_controller_spec.rb +22 -6
- data/spec/controllers/admin/pages_controller_spec.rb +41 -58
- data/spec/controllers/admin/resources_controller_spec.rb +30 -5
- data/spec/controllers/admin/trash_controller_spec.rb +1 -1
- data/spec/controllers/attachments_controller_spec.rb +26 -44
- data/spec/controllers/base_controller_spec.rb +8 -33
- data/spec/controllers/elements_controller_spec.rb +1 -1
- data/spec/controllers/pages_controller_spec.rb +7 -15
- data/spec/controllers/pictures_controller_spec.rb +44 -5
- data/spec/dummy/app/controllers/application_controller.rb +9 -1
- data/spec/dummy/app/models/user.rb +14 -0
- data/spec/dummy/db/migrate/20130827094554_alchemy_two_point_six.rb +0 -31
- data/spec/dummy/db/schema.rb +0 -31
- data/spec/features/admin/language_tree_feature_spec.rb +34 -0
- data/spec/features/admin/pages_controller_spec.rb +1 -1
- data/spec/features/pages_controller_spec.rb +5 -12
- data/spec/features/picture_security_spec.rb +2 -2
- data/spec/features/security_spec.rb +6 -45
- data/spec/features/translation_integration_spec.rb +11 -20
- data/spec/{support → fixtures}/80x60.png +0 -0
- data/spec/support/image with spaces.png b/data/spec/fixtures/image with → spaces.png +0 -0
- data/spec/{support → fixtures}/image.png +0 -0
- data/spec/{support → fixtures}/image2.PNG +0 -0
- data/spec/{support → fixtures}/image3.jpeg +0 -0
- data/spec/helpers/admin/base_helper_spec.rb +31 -43
- data/spec/helpers/admin/pages_helper_spec.rb +4 -2
- data/spec/helpers/base_helper_spec.rb +10 -3
- data/spec/helpers/pages_helper_spec.rb +32 -22
- data/spec/models/attachment_spec.rb +1 -1
- data/spec/models/element_spec.rb +33 -57
- data/spec/models/message_spec.rb +0 -16
- data/spec/models/page_spec.rb +62 -26
- data/spec/models/picture_spec.rb +5 -5
- data/spec/spec_helper.rb +13 -4
- data/spec/tasks/helpers_spec.rb +213 -0
- metadata +33 -75
- data/app/controllers/alchemy/passwords_controller.rb +0 -35
- data/app/controllers/alchemy/user_sessions_controller.rb +0 -67
- data/app/controllers/alchemy/users_controller.rb +0 -46
- data/app/mailers/alchemy/notifications.rb +0 -33
- data/app/models/alchemy/page/users.rb +0 -25
- data/app/models/alchemy/user.rb +0 -183
- data/app/views/alchemy/admin/users/_table.html.erb +0 -69
- data/app/views/alchemy/admin/users/_user.html.erb +0 -39
- data/app/views/alchemy/admin/users/edit.html.erb +0 -6
- data/app/views/alchemy/admin/users/index.html.erb +0 -58
- data/app/views/alchemy/admin/users/new.html.erb +0 -6
- data/app/views/alchemy/notifications/admin_user_created.de.text.erb +0 -15
- data/app/views/alchemy/notifications/admin_user_created.en.text.erb +0 -15
- data/app/views/alchemy/notifications/registered_user_created.de.text.erb +0 -13
- data/app/views/alchemy/notifications/registered_user_created.en.text.erb +0 -13
- data/app/views/alchemy/notifications/reset_password_instructions.de.text.erb +0 -8
- data/app/views/alchemy/notifications/reset_password_instructions.en.text.erb +0 -8
- data/app/views/alchemy/passwords/edit.html.erb +0 -35
- data/app/views/alchemy/passwords/new.html.erb +0 -30
- data/app/views/alchemy/user_sessions/new.html.erb +0 -48
- data/app/views/alchemy/users/new.html.erb +0 -14
- data/config/initializers/devise.rb +0 -242
- data/config/locales/devise.de.yml +0 -58
- data/config/locales/devise.en.yml +0 -60
- data/lib/rails/generators/alchemy/devise/devise_generator.rb +0 -29
- data/spec/controllers/admin/users_controller_spec.rb +0 -132
- data/spec/controllers/passwords_controller_spec.rb +0 -16
- data/spec/controllers/user_sessions_controller_spec.rb +0 -22
- data/spec/controllers/users_controller_spec.rb +0 -66
- data/spec/mailers/notifications_spec.rb +0 -67
- data/spec/models/user_spec.rb +0 -252
- data/spec/support/alchemy/controller_helpers.rb +0 -35
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# Provides authentication accessors.
|
|
2
|
+
#
|
|
3
|
+
# Alchemy has some defaults for user model name and login logout path names:
|
|
4
|
+
#
|
|
5
|
+
# +Alchemy.user_class_name+ defaults to +'User'+
|
|
6
|
+
# +Alchemy.login_path defaults to +'/login'+
|
|
7
|
+
# +Alchemy.logout_path defaults to +'/admin/logout'+
|
|
8
|
+
#
|
|
9
|
+
# Anyway, you can tell Alchemy about your authentication model configuration:
|
|
10
|
+
#
|
|
11
|
+
# 1. Your user class name - @see: Alchemy.user_class
|
|
12
|
+
# 2. The path to the login form - @see: Alchemy.login_path
|
|
13
|
+
# 3. The path to the logout method - @see: Alchemy.logout_path
|
|
14
|
+
#
|
|
15
|
+
# == Example
|
|
16
|
+
#
|
|
17
|
+
# # config/initializers/alchemy.rb
|
|
18
|
+
# Alchemy.user_class_name = 'Admin'
|
|
19
|
+
# Alchemy.login_path = '/auth/login'
|
|
20
|
+
# Alchemy.logout_path = '/auth/logout'
|
|
21
|
+
#
|
|
22
|
+
# If you don't have your own user model or don't want to provide one,
|
|
23
|
+
# add the `alchemy-devise` gem into your App's Gemfile.
|
|
24
|
+
#
|
|
25
|
+
module Alchemy
|
|
26
|
+
mattr_accessor :user_class_name, :login_path, :logout_path
|
|
27
|
+
|
|
28
|
+
# Defaults
|
|
29
|
+
#
|
|
30
|
+
@@user_class_name = 'User'
|
|
31
|
+
@@login_path = '/login'
|
|
32
|
+
@@logout_path = '/logout'
|
|
33
|
+
|
|
34
|
+
# Returns the user class
|
|
35
|
+
#
|
|
36
|
+
# Set your App's user class to Alchemy.user_class_name in an initializer.
|
|
37
|
+
#
|
|
38
|
+
# Defaults to +User+
|
|
39
|
+
#
|
|
40
|
+
# == Example
|
|
41
|
+
#
|
|
42
|
+
# # config/initializers/alchemy.rb
|
|
43
|
+
# Alchemy.user_class_name = 'Admin'
|
|
44
|
+
#
|
|
45
|
+
def self.user_class
|
|
46
|
+
@@user_class ||= begin
|
|
47
|
+
if @@user_class_name.is_a?(String)
|
|
48
|
+
@@user_class_name.constantize
|
|
49
|
+
else
|
|
50
|
+
raise 'Alchemy.user_class_name must be a String, not a Class.'
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
data/lib/alchemy/capistrano.rb
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
# This recipe contains Capistrano recipes for handling the uploads, ferret index and picture cache files while deploying your application.
|
|
2
2
|
# It also contains a ferret:rebuild_index task to rebuild the index after deploying your application.
|
|
3
3
|
require 'fileutils'
|
|
4
|
+
require 'alchemy/tasks/helpers'
|
|
5
|
+
|
|
6
|
+
include Alchemy::Tasks::Helpers
|
|
4
7
|
|
|
5
8
|
::Capistrano::Configuration.instance(:must_exist).load do
|
|
6
9
|
|
|
@@ -100,7 +103,7 @@ EOF
|
|
|
100
103
|
database
|
|
101
104
|
end
|
|
102
105
|
|
|
103
|
-
desc "Imports the database into your local development machine."
|
|
106
|
+
desc "Imports the server database into your local development machine."
|
|
104
107
|
task :database, :roles => [:db], :only => {:primary => true} do
|
|
105
108
|
require 'spinner'
|
|
106
109
|
server = find_servers_for_task(current_task).first
|
|
@@ -147,23 +150,8 @@ EOF
|
|
|
147
150
|
def db_import_cmd(server)
|
|
148
151
|
dump_cmd = "cd #{current_path} && #{rake} RAILS_ENV=#{fetch(:rails_env, 'production')} alchemy:db:dump"
|
|
149
152
|
sql_stream = "ssh -p #{fetch(:port, 22)} #{user}@#{server} '#{dump_cmd}'"
|
|
150
|
-
"#{sql_stream} |
|
|
153
|
+
"#{sql_stream} | #{database_import_command(database_config['adapter'])} 1>/dev/null 2>&1"
|
|
151
154
|
end
|
|
152
|
-
|
|
153
|
-
def mysql_credentials
|
|
154
|
-
mysql_credentials = []
|
|
155
|
-
if database_config['username']
|
|
156
|
-
mysql_credentials << "--user='#{database_config['username']}'"
|
|
157
|
-
end
|
|
158
|
-
if database_config['password']
|
|
159
|
-
mysql_credentials << "--password='#{database_config['password']}'"
|
|
160
|
-
end
|
|
161
|
-
if (host = database_config['host']) && (host != 'localhost')
|
|
162
|
-
mysql_credentials << "--host='#{host}'"
|
|
163
|
-
end
|
|
164
|
-
mysql_credentials.join(' ')
|
|
165
|
-
end
|
|
166
|
-
|
|
167
155
|
end
|
|
168
156
|
|
|
169
157
|
end
|
data/lib/alchemy/engine.rb
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
require 'coffee-rails'
|
|
3
3
|
require 'compass-rails'
|
|
4
4
|
require 'declarative_authorization'
|
|
5
|
-
require 'devise'
|
|
6
5
|
require 'dynamic_form'
|
|
7
6
|
require 'jquery-rails'
|
|
8
7
|
require 'jquery-ui-rails'
|
|
@@ -10,9 +9,11 @@ require 'kaminari'
|
|
|
10
9
|
require 'rails3-jquery-autocomplete'
|
|
11
10
|
require 'sass-rails'
|
|
12
11
|
require 'sassy-buttons'
|
|
12
|
+
require 'userstamp'
|
|
13
13
|
|
|
14
14
|
# Require globally used Alchemy mixins
|
|
15
15
|
require 'alchemy/auth/engine'
|
|
16
|
+
require 'alchemy/auth_accessors'
|
|
16
17
|
require 'alchemy/config'
|
|
17
18
|
require 'alchemy/errors'
|
|
18
19
|
require 'alchemy/essence'
|
|
@@ -26,6 +27,7 @@ require 'alchemy/mount_point'
|
|
|
26
27
|
require 'alchemy/name_conversions'
|
|
27
28
|
require 'alchemy/page_layout'
|
|
28
29
|
require 'alchemy/picture_attributes'
|
|
30
|
+
require 'alchemy/resource'
|
|
29
31
|
require 'alchemy/tinymce'
|
|
30
32
|
|
|
31
33
|
# Require hacks
|
|
@@ -37,7 +39,6 @@ require File.join(File.dirname(__FILE__), '../middleware/flash_session_cookie')
|
|
|
37
39
|
|
|
38
40
|
module Alchemy
|
|
39
41
|
class Engine < Rails::Engine
|
|
40
|
-
|
|
41
42
|
isolate_namespace Alchemy
|
|
42
43
|
engine_name 'alchemy'
|
|
43
44
|
config.mount_at = '/'
|
|
@@ -65,11 +66,6 @@ module Alchemy
|
|
|
65
66
|
)
|
|
66
67
|
end
|
|
67
68
|
|
|
68
|
-
# filter sensitive information during logging
|
|
69
|
-
initializer "alchemy.params.filter" do |app|
|
|
70
|
-
app.config.filter_parameters += [:password, :password_confirmation]
|
|
71
|
-
end
|
|
72
|
-
|
|
73
69
|
initializer "alchemy.add_authorization_rules" do
|
|
74
70
|
Alchemy::Auth::Engine.get_instance.load(File.join(File.dirname(__FILE__), '../..', 'config/authorization_rules.rb'))
|
|
75
71
|
end
|
|
@@ -78,5 +74,9 @@ module Alchemy
|
|
|
78
74
|
ApplicationController.send(:include, Alchemy::LanguageHelpers)
|
|
79
75
|
end
|
|
80
76
|
|
|
77
|
+
config.after_initialize do
|
|
78
|
+
require 'alchemy/userstamp'
|
|
79
|
+
end
|
|
80
|
+
|
|
81
81
|
end
|
|
82
82
|
end
|
data/lib/alchemy/errors.rb
CHANGED
|
@@ -56,4 +56,10 @@ module Alchemy
|
|
|
56
56
|
end
|
|
57
57
|
end
|
|
58
58
|
|
|
59
|
+
class NoCurrentUserFoundError < StandardError
|
|
60
|
+
# Raised if no current_user is found to authorize against.
|
|
61
|
+
def message
|
|
62
|
+
"You need to provide a current_user method in your ApplicationController that returns the current authenticated user."
|
|
63
|
+
end
|
|
64
|
+
end
|
|
59
65
|
end
|
data/lib/alchemy/essence.rb
CHANGED
|
@@ -32,7 +32,7 @@ module Alchemy #:nodoc:
|
|
|
32
32
|
attr_accessor :validation_errors
|
|
33
33
|
attr_accessible :ingredient
|
|
34
34
|
include Alchemy::Essence::InstanceMethods
|
|
35
|
-
stampable
|
|
35
|
+
stampable stamper_class_name: Alchemy.user_class_name
|
|
36
36
|
validate :essence_validations, :on => :update
|
|
37
37
|
has_many :contents, :as => :essence
|
|
38
38
|
has_many :elements, :through => :contents
|
|
@@ -106,7 +106,7 @@ module Alchemy #:nodoc:
|
|
|
106
106
|
case description['validate_format_as']
|
|
107
107
|
when 'email'
|
|
108
108
|
then
|
|
109
|
-
matcher =
|
|
109
|
+
matcher = Alchemy::Config.get(:email_regexp)
|
|
110
110
|
when 'url'
|
|
111
111
|
then
|
|
112
112
|
matcher = /^[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$/ix
|
data/lib/alchemy/seeder.rb
CHANGED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
module Alchemy
|
|
2
|
+
module Tasks
|
|
3
|
+
module Helpers
|
|
4
|
+
|
|
5
|
+
def database_dump_command(adapter)
|
|
6
|
+
database_command(adapter, 'dump')
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def database_import_command(adapter)
|
|
10
|
+
database_command(adapter, 'import')
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def database_config
|
|
14
|
+
raise "Could not find #{database_config_file}!" if !File.exists?(database_config_file)
|
|
15
|
+
@database_config ||= begin
|
|
16
|
+
config_file = YAML.load_file(database_config_file)
|
|
17
|
+
config_file.fetch(environment)
|
|
18
|
+
rescue KeyError
|
|
19
|
+
raise "Database configuration for #{environment} not found!"
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
private
|
|
24
|
+
|
|
25
|
+
def database_command(adapter, action='import')
|
|
26
|
+
case adapter.to_s
|
|
27
|
+
when /mysql/
|
|
28
|
+
"#{mysql_command(mysql_command_for(action))} #{database_config['database']}"
|
|
29
|
+
when /postgresql/
|
|
30
|
+
"#{postgres_command(postgres_command_for(action))} #{database_config['database']}"
|
|
31
|
+
else
|
|
32
|
+
raise ArgumentError, "Alchemy only supports #{action}ing MySQL and PostgreSQL databases. #{adapter} is not supported."
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def mysql_command(cmd='mysql')
|
|
37
|
+
command = [cmd]
|
|
38
|
+
if database_config['username']
|
|
39
|
+
command << "--user='#{database_config['username']}'"
|
|
40
|
+
end
|
|
41
|
+
if database_config['password']
|
|
42
|
+
command << "--password='#{database_config['password']}'"
|
|
43
|
+
end
|
|
44
|
+
if (host = database_config['host']) && (host != 'localhost')
|
|
45
|
+
command << "--host='#{host}'"
|
|
46
|
+
end
|
|
47
|
+
command.join(' ')
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def postgres_command(cmd='psql')
|
|
51
|
+
command = []
|
|
52
|
+
if database_config['password']
|
|
53
|
+
command << "PGPASSWORD='#{database_config['password']}'"
|
|
54
|
+
end
|
|
55
|
+
command << cmd
|
|
56
|
+
if database_config['username']
|
|
57
|
+
command << "--username='#{database_config['username']}'"
|
|
58
|
+
end
|
|
59
|
+
if (host = database_config['host']) && (host != 'localhost')
|
|
60
|
+
command << "--host='#{host}'"
|
|
61
|
+
end
|
|
62
|
+
command.join(' ')
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def mysql_command_for(action)
|
|
66
|
+
action == 'import' ? 'mysql' : 'mysqldump'
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def postgres_command_for(action)
|
|
70
|
+
action == 'import' ? 'psql' : 'pg_dump --clean'
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def database_config_file
|
|
74
|
+
"./config/database.yml"
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def environment
|
|
78
|
+
ENV['RAILS_ENV'] || 'development'
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
module Alchemy
|
|
2
|
+
module TestSupport
|
|
3
|
+
|
|
4
|
+
# Helpers for authentication
|
|
5
|
+
#
|
|
6
|
+
module AuthHelpers
|
|
7
|
+
|
|
8
|
+
def sign_in(user = admin_user)
|
|
9
|
+
controller.stub current_alchemy_user: user
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def registered_user
|
|
13
|
+
mock_user([:registered])
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def author_user
|
|
17
|
+
mock_user([:author])
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def editor_user
|
|
21
|
+
mock_user([:editor])
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def admin_user
|
|
25
|
+
mock_user([:admin])
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def mock_user(roles)
|
|
29
|
+
mock_model(Alchemy.user_class, alchemy_roles: roles.map(&:to_sym), role_symbols: roles.map(&:to_sym))
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
end
|
|
35
|
+
end
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# Based on spree commerce controller hacks.
|
|
2
|
+
# https://github.com/spree/spree/blob/master/core/spec/support/controller_hacks.rb
|
|
3
|
+
# Thanks!
|
|
4
|
+
|
|
5
|
+
module Alchemy
|
|
6
|
+
module TestSupport
|
|
7
|
+
module ControllerRequests
|
|
8
|
+
|
|
9
|
+
def get(action, parameters = nil, session = nil, flash = nil)
|
|
10
|
+
process_alchemy_action(action, parameters, session, flash, "GET")
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
# Executes a request simulating POST HTTP method and set/volley the response
|
|
14
|
+
def post(action, parameters = nil, session = nil, flash = nil)
|
|
15
|
+
process_alchemy_action(action, parameters, session, flash, "POST")
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# Executes a request simulating PUT HTTP method and set/volley the response
|
|
19
|
+
def put(action, parameters = nil, session = nil, flash = nil)
|
|
20
|
+
process_alchemy_action(action, parameters, session, flash, "PUT")
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# Executes a request simulating DELETE HTTP method and set/volley the response
|
|
24
|
+
def delete(action, parameters = nil, session = nil, flash = nil)
|
|
25
|
+
process_alchemy_action(action, parameters, session, flash, "DELETE")
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
private
|
|
29
|
+
|
|
30
|
+
def process_alchemy_action(action, parameters = nil, session = nil, flash = nil, method = "GET")
|
|
31
|
+
parameters ||= {}
|
|
32
|
+
process(action, parameters.merge!(:use_route => :alchemy), session, flash, method)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
@@ -1,32 +1,5 @@
|
|
|
1
1
|
FactoryGirl.define do
|
|
2
2
|
|
|
3
|
-
factory :user, :class => 'Alchemy::User' do
|
|
4
|
-
firstname "John"
|
|
5
|
-
lastname "Doe"
|
|
6
|
-
email 'john@doe.com'
|
|
7
|
-
login "jdoe"
|
|
8
|
-
password 's3cr3t'
|
|
9
|
-
password_confirmation 's3cr3t'
|
|
10
|
-
language 'en'
|
|
11
|
-
|
|
12
|
-
factory :admin_user do
|
|
13
|
-
roles 'admin'
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
factory :registered_user do
|
|
17
|
-
roles 'registered'
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
factory :author_user do
|
|
21
|
-
roles 'author'
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
factory :editor_user do
|
|
25
|
-
roles 'editor'
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
end
|
|
29
|
-
|
|
30
3
|
factory :language, :class => 'Alchemy::Language' do
|
|
31
4
|
name 'Deutsch'
|
|
32
5
|
code 'de'
|
|
@@ -105,7 +78,7 @@ FactoryGirl.define do
|
|
|
105
78
|
end
|
|
106
79
|
|
|
107
80
|
factory :picture, :class => 'Alchemy::Picture' do
|
|
108
|
-
image_file File.new(File.expand_path('
|
|
81
|
+
image_file File.new(File.expand_path('../../../../spec/fixtures/image.png', __FILE__))
|
|
109
82
|
name 'image'
|
|
110
83
|
image_file_name 'image.png'
|
|
111
84
|
upload_hash Time.now.hash
|
|
@@ -125,4 +98,10 @@ FactoryGirl.define do
|
|
|
125
98
|
name 'A Site'
|
|
126
99
|
host 'domain.com'
|
|
127
100
|
end
|
|
101
|
+
|
|
102
|
+
factory :attachment, :class => 'Alchemy::Attachment' do
|
|
103
|
+
file File.new(File.expand_path('../../../../spec/fixtures/image.png', __FILE__))
|
|
104
|
+
name 'image'
|
|
105
|
+
file_name 'image.png'
|
|
106
|
+
end
|
|
128
107
|
end
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
require 'declarative_authorization/maintenance'
|
|
2
2
|
|
|
3
3
|
module Alchemy
|
|
4
|
-
module
|
|
4
|
+
module TestSupport
|
|
5
5
|
|
|
6
6
|
# Helpers for integration specs
|
|
7
7
|
#
|
|
@@ -10,31 +10,19 @@ module Alchemy
|
|
|
10
10
|
module IntegrationHelpers
|
|
11
11
|
include ::Authorization::TestHelper
|
|
12
12
|
|
|
13
|
-
#
|
|
13
|
+
# Used in Capybara features specs. Stubs the current_alchemy_user
|
|
14
14
|
#
|
|
15
|
-
#
|
|
16
|
-
# * login_into_alchemy
|
|
15
|
+
# It mocks an admin user, but you can pass in a user object that would be used as stub.
|
|
17
16
|
#
|
|
18
|
-
def authorize_as_admin
|
|
19
|
-
create_admin_user
|
|
20
|
-
login_into_alchemy
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
# Capybara actions to login into Alchemy Backend
|
|
24
|
-
#
|
|
25
|
-
# You should have a admin user before loggin in.
|
|
26
|
-
#
|
|
27
|
-
# See: create_admin_user method
|
|
28
|
-
#
|
|
29
|
-
def login_into_alchemy
|
|
17
|
+
def authorize_as_admin(user=nil)
|
|
30
18
|
# Ensure that phantomjs has always the same browser language.
|
|
31
19
|
if Capybara.current_driver == :poltergeist
|
|
32
20
|
page.driver.headers = { 'Accept-Language' => 'en' }
|
|
33
21
|
end
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
22
|
+
if !user
|
|
23
|
+
user = mock_model('DummyUser', alchemy_roles: %w(admin), role_symbols: [:admin], language: 'en')
|
|
24
|
+
end
|
|
25
|
+
ApplicationController.any_instance.stub(:current_user).and_return(user)
|
|
38
26
|
end
|
|
39
27
|
|
|
40
28
|
# Load additional authorization_rules for specs.
|
|
@@ -43,21 +31,7 @@ module Alchemy
|
|
|
43
31
|
#
|
|
44
32
|
def load_authorization_rules
|
|
45
33
|
instance = Alchemy::Auth::Engine.get_instance
|
|
46
|
-
instance.load(File.join(File.dirname(__FILE__), '
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
# Creates an admin user in a way it works
|
|
50
|
-
#
|
|
51
|
-
# You should create it once in a before block
|
|
52
|
-
#
|
|
53
|
-
# === Example:
|
|
54
|
-
#
|
|
55
|
-
# before do
|
|
56
|
-
# create_admin_user
|
|
57
|
-
# end
|
|
58
|
-
#
|
|
59
|
-
def create_admin_user
|
|
60
|
-
FactoryGirl.create(:admin_user)
|
|
34
|
+
instance.load(File.join(File.dirname(__FILE__), '../../../spec/dummy', 'config/authorization_rules.rb'))
|
|
61
35
|
end
|
|
62
36
|
|
|
63
37
|
# Capybara actions to create a new element.
|
|
@@ -73,7 +47,6 @@ module Alchemy
|
|
|
73
47
|
click_button 'Add'
|
|
74
48
|
end
|
|
75
49
|
end
|
|
76
|
-
|
|
77
50
|
end
|
|
78
51
|
|
|
79
52
|
end
|