enju_leaf 1.1.0.rc17 → 1.1.0.rc18
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +1 -1
- data/app/controllers/user_export_files_controller.rb +4 -3
- data/app/controllers/user_groups_controller.rb +5 -1
- data/app/controllers/user_import_files_controller.rb +2 -2
- data/app/models/profile.rb +10 -5
- data/app/models/role.rb +2 -2
- data/app/models/user_export_file.rb +16 -11
- data/app/models/user_export_file_transition.rb +4 -4
- data/app/models/user_group.rb +3 -3
- data/app/models/user_has_role.rb +2 -2
- data/app/models/user_import_file.rb +19 -10
- data/app/models/user_import_file_transition.rb +4 -4
- data/app/models/user_import_result.rb +3 -2
- data/app/views/layouts/application.html.erb +1 -1
- data/app/views/my_accounts/_edit_credential.html.erb +1 -1
- data/app/views/page/_menu.html.erb +2 -2
- data/app/views/page/advanced_search.html.erb +12 -0
- data/app/views/user_export_files/show.html.erb +5 -0
- data/app/workers/user_export_file_queue.rb +1 -1
- data/app/workers/user_import_file_queue.rb +1 -1
- data/config/initializers/redis.rb +3 -0
- data/config/locales/simple_form.ja.yml +1 -1
- data/db/migrate/20150506105356_add_error_message_to_user_import_result.rb +5 -0
- data/lib/enju_leaf.rb +5 -6
- data/lib/enju_leaf/calculate_stat.rb +2 -2
- data/lib/enju_leaf/engine.rb +1 -2
- data/lib/enju_leaf/export_file.rb +2 -2
- data/lib/enju_leaf/helper.rb +8 -9
- data/lib/enju_leaf/import_file.rb +8 -8
- data/lib/enju_leaf/user.rb +15 -15
- data/lib/enju_leaf/version.rb +1 -1
- data/lib/generators/enju_leaf/quick_install/quick_install_generator.rb +7 -14
- data/lib/generators/enju_leaf/setup/setup_generator.rb +23 -16
- data/spec/controllers/my_accounts_controller_spec.rb +7 -6
- data/spec/controllers/profiles_controller_spec.rb +12 -12
- data/spec/controllers/roles_controller_spec.rb +12 -12
- data/spec/controllers/user_export_files_controller_spec.rb +20 -20
- data/spec/controllers/user_groups_controller_spec.rb +47 -47
- data/spec/controllers/user_import_files_controller_spec.rb +20 -20
- data/spec/controllers/user_import_results_controller_spec.rb +12 -12
- data/spec/dummy/app/controllers/application_controller.rb +1 -1
- data/spec/dummy/config/initializers/devise.rb +1 -1
- data/spec/dummy/db/migrate/20150221063719_add_settings_to_library_group.rb +5 -0
- data/spec/dummy/db/schema.rb +3 -1
- data/spec/factories/user.rb +4 -4
- data/spec/fixtures/library_groups.yml +27 -22
- data/spec/fixtures/profiles.yml +10 -5
- data/spec/fixtures/roles.yml +2 -2
- data/spec/fixtures/user_export_files.yml +8 -9
- data/spec/fixtures/user_groups.yml +3 -3
- data/spec/fixtures/user_has_roles.yml +2 -2
- data/spec/fixtures/user_import_files.yml +10 -8
- data/spec/fixtures/user_import_results.yml +3 -2
- data/spec/models/profile_spec.rb +25 -0
- data/spec/models/role_spec.rb +2 -2
- data/spec/models/user_export_file_spec.rb +8 -9
- data/spec/models/user_group_spec.rb +3 -3
- data/spec/models/user_has_role_spec.rb +2 -2
- data/spec/models/user_import_file_spec.rb +19 -16
- data/spec/models/user_import_result_spec.rb +3 -2
- data/spec/routing/accounts_spec.rb +2 -2
- data/spec/routing/profiles_routing_spec.rb +7 -7
- data/spec/routing/resource_import_files_routing_spec.rb +4 -4
- data/spec/views/profiles/new.html.erb_spec.rb +2 -2
- metadata +33 -33
- data/app/models/setting.rb +0 -4
- data/lib/generators/enju_leaf/setup/templates/config/application.yml +0 -48
- data/spec/dummy/app/models/setting.rb +0 -4
@@ -14,10 +14,10 @@ module ExportFile
|
|
14
14
|
|
15
15
|
module InstanceMethods
|
16
16
|
def send_message
|
17
|
-
sender = User.find(1)
|
17
|
+
sender = User.find(1) #system
|
18
18
|
message_template = MessageTemplate.localized_template('export_completed', user.profile.locale)
|
19
19
|
request = MessageRequest.new
|
20
|
-
request.assign_attributes({:
|
20
|
+
request.assign_attributes({sender: sender, receiver: user, message_template: message_template})
|
21
21
|
request.save_message_body
|
22
22
|
request.transition_to!(:sent)
|
23
23
|
end
|
data/lib/enju_leaf/helper.rb
CHANGED
@@ -29,15 +29,15 @@ module EnjuLeaf
|
|
29
29
|
end
|
30
30
|
|
31
31
|
def locale_display_name(locale)
|
32
|
-
Language.where(:
|
32
|
+
Language.where(iso_639_1: locale).first.display_name
|
33
33
|
end
|
34
34
|
|
35
35
|
def locale_native_name(locale)
|
36
|
-
Language.where(:
|
36
|
+
Language.where(iso_639_1: locale).first.native_name
|
37
37
|
end
|
38
38
|
|
39
39
|
def move_position(object)
|
40
|
-
render :
|
40
|
+
render partial: 'page/position', locals: {object: object}
|
41
41
|
end
|
42
42
|
|
43
43
|
def localized_state(state)
|
@@ -91,7 +91,7 @@ module EnjuLeaf
|
|
91
91
|
options.delete(:page) if options[:page].to_i == 1
|
92
92
|
end
|
93
93
|
unless controller_name == 'test'
|
94
|
-
link_to t('page.listing', :
|
94
|
+
link_to t('page.listing', model: t("activerecord.models.#{controller_name.singularize}")), url_for(params.merge(controller: controller_name, action: :index, id: nil, only_path: true).merge(options))
|
95
95
|
end
|
96
96
|
end
|
97
97
|
|
@@ -101,15 +101,14 @@ module EnjuLeaf
|
|
101
101
|
|
102
102
|
def markdown_helper(string)
|
103
103
|
return unless string
|
104
|
-
if defined?(
|
105
|
-
string
|
106
|
-
# Kramdown::Document.new(string.to_s).to_html.html_safe
|
107
|
-
else
|
104
|
+
if defined?(Redcarpet)
|
108
105
|
markdown = Redcarpet::Markdown.new(
|
109
106
|
Redcarpet::Render::HTML,
|
110
|
-
:
|
107
|
+
autolink: true, safe_links_only: true
|
111
108
|
)
|
112
109
|
markdown.render(string.to_s).html_safe
|
110
|
+
else
|
111
|
+
Kramdown::Document.new(string.to_s).to_html.html_safe
|
113
112
|
end
|
114
113
|
end
|
115
114
|
|
@@ -72,21 +72,21 @@ module ImportFile
|
|
72
72
|
else
|
73
73
|
output_encoding = '-w'
|
74
74
|
end
|
75
|
-
|
75
|
+
NKF.nkf("#{output_encoding} -Lu", line)
|
76
76
|
end
|
77
77
|
|
78
78
|
def create_import_temp_file(attachment)
|
79
79
|
tempfile = Tempfile.new(self.class.name.underscore)
|
80
|
-
if
|
81
|
-
|
80
|
+
if ENV['ENJU_STORAGE'] == 's3'
|
81
|
+
tempfile.write Faraday.get(attachment.expiring_url(10)).body.force_encoding('UTF-8')
|
82
82
|
else
|
83
83
|
uploaded_file_path = attachment.path
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
84
|
+
open(uploaded_file_path){|f|
|
85
|
+
f.each{|line|
|
86
|
+
tempfile.puts(convert_encoding(line))
|
87
|
+
}
|
88
88
|
}
|
89
|
-
|
89
|
+
end
|
90
90
|
tempfile.close
|
91
91
|
tempfile
|
92
92
|
end
|
data/lib/enju_leaf/user.rb
CHANGED
@@ -19,7 +19,7 @@ module EnjuLeaf
|
|
19
19
|
# :expired_at, :locked, :role_id,
|
20
20
|
# :user_has_role_attributes, :auto_generated_password,
|
21
21
|
# :profile_attributes,
|
22
|
-
# :
|
22
|
+
# as: :admin
|
23
23
|
|
24
24
|
scope :administrators, -> { joins(:role).where('roles.name = ?', 'Administrator') }
|
25
25
|
scope :librarians, -> { joins(:role).where('roles.name = ? OR roles.name = ?', 'Administrator', 'Librarian') }
|
@@ -27,10 +27,10 @@ module EnjuLeaf
|
|
27
27
|
has_one :profile
|
28
28
|
if defined?(EnjuBiblio)
|
29
29
|
has_many :import_requests
|
30
|
-
has_many :picture_files, :
|
30
|
+
has_many :picture_files, as: :picture_attachable, dependent: :destroy
|
31
31
|
end
|
32
|
-
has_one :user_has_role, :
|
33
|
-
has_one :role, :
|
32
|
+
has_one :user_has_role, dependent: :destroy
|
33
|
+
has_one :role, through: :user_has_role
|
34
34
|
belongs_to :user_group
|
35
35
|
belongs_to :library
|
36
36
|
belongs_to :required_role, class_name: 'Role', foreign_key: 'required_role_id'
|
@@ -39,18 +39,18 @@ module EnjuLeaf
|
|
39
39
|
validates :username, presence: true, uniqueness: true, format: {
|
40
40
|
with: /\A[0-9A-Za-z][0-9A-Za-z_\-]*[0-9A-Za-z]\Z/
|
41
41
|
}
|
42
|
-
validates :email, :
|
43
|
-
validates_date :expired_at, :
|
42
|
+
validates :email, format: Devise::email_regexp, allow_blank: true, uniqueness: true
|
43
|
+
validates_date :expired_at, allow_blank: true
|
44
44
|
|
45
|
-
with_options :
|
45
|
+
with_options if: :password_required? do |v|
|
46
46
|
v.validates_presence_of :password
|
47
47
|
v.validates_confirmation_of :password
|
48
|
-
v.validates_length_of :password, :
|
49
|
-
:
|
48
|
+
v.validates_length_of :password, allow_blank: true,
|
49
|
+
within: Devise::password_length
|
50
50
|
end
|
51
51
|
|
52
|
-
validates_presence_of :email, :email_confirmation, :
|
53
|
-
validates_confirmation_of :email, :
|
52
|
+
validates_presence_of :email, :email_confirmation, on: :create, if: proc{|user| !user.operator.try(:has_role?, 'Librarian')}
|
53
|
+
validates_confirmation_of :email, on: :create #, if: proc{|user| !user.operator.try(:has_role?, 'Librarian')}
|
54
54
|
|
55
55
|
before_validation :set_lock_information
|
56
56
|
before_destroy :check_role_before_destroy
|
@@ -61,7 +61,7 @@ module EnjuLeaf
|
|
61
61
|
friendly_id :username
|
62
62
|
#has_paper_trail
|
63
63
|
normalize_attributes :username
|
64
|
-
normalize_attributes :email, :
|
64
|
+
normalize_attributes :email, with: :strip
|
65
65
|
|
66
66
|
attr_accessor :operator, :password_not_verified,
|
67
67
|
:update_own_account, :auto_generated_password,
|
@@ -178,7 +178,7 @@ module EnjuLeaf
|
|
178
178
|
|
179
179
|
def check_role_before_destroy
|
180
180
|
if self.has_role?('Administrator')
|
181
|
-
raise 'This is the last administrator in this system.' if Role.where(:
|
181
|
+
raise 'This is the last administrator in this system.' if Role.where(name: 'Administrator').first.users.size == 1
|
182
182
|
end
|
183
183
|
end
|
184
184
|
|
@@ -200,7 +200,7 @@ module EnjuLeaf
|
|
200
200
|
|
201
201
|
def last_librarian?
|
202
202
|
if self.has_role?('Librarian')
|
203
|
-
role = Role.where(:
|
203
|
+
role = Role.where(name: 'Librarian').first
|
204
204
|
true if role.users.size == 1
|
205
205
|
end
|
206
206
|
end
|
@@ -232,7 +232,7 @@ module EnjuLeaf
|
|
232
232
|
|
233
233
|
# 最後の管理者を削除しようとした
|
234
234
|
if has_role?('Administrator')
|
235
|
-
if Role.where(:
|
235
|
+
if Role.where(name: 'Administrator').first.users.size == 1
|
236
236
|
errors[:base] << I18n.t('user.last_administrator')
|
237
237
|
end
|
238
238
|
end
|
data/lib/enju_leaf/version.rb
CHANGED
@@ -2,22 +2,15 @@ class EnjuLeaf::QuickInstallGenerator < Rails::Generators::Base
|
|
2
2
|
source_root File.expand_path('../templates', __FILE__)
|
3
3
|
|
4
4
|
def quick_install
|
5
|
-
environment = ENV['
|
5
|
+
environment = ENV['RAILS_ENV'] || 'development'
|
6
|
+
rake("enju_leaf_engine:install:migrations")
|
7
|
+
rake("enju_biblio_engine:install:migrations")
|
8
|
+
rake("enju_library_engine:install:migrations")
|
6
9
|
if !ENV['SKIP_CONFIG']
|
7
|
-
|
10
|
+
generate("enju_biblio:setup")
|
11
|
+
generate("enju_library:setup")
|
8
12
|
generate("enju_circulation:setup")
|
9
13
|
generate("enju_subject:setup")
|
10
|
-
gsub_file 'config/schedule.rb', /^set :environment, :development$/,
|
11
|
-
"set :environment, :#{environment}"
|
12
|
-
gsub_file 'config/environments/production.rb',
|
13
|
-
/config.serve_static_assets = false$/,
|
14
|
-
"config.serve_static_assets = true"
|
15
|
-
gsub_file 'config/environments/production.rb',
|
16
|
-
/# config.cache_store = :mem_cache_store$/,
|
17
|
-
"config.cache_store = :dalli_store, {:compress => true}"
|
18
|
-
gsub_file 'config/environments/production.rb',
|
19
|
-
/# config.assets.precompile \+= %w\( search.js \)$/,
|
20
|
-
"config.assets.precompile += %w( mobile.js mobile.css print.css )"
|
21
14
|
end
|
22
15
|
rake("db:migrate", env: environment)
|
23
16
|
rake("enju_leaf:setup", env: environment)
|
@@ -30,7 +23,7 @@ class EnjuLeaf::QuickInstallGenerator < Rails::Generators::Base
|
|
30
23
|
else
|
31
24
|
rake("sunspot:solr:start", env: environment)
|
32
25
|
sleep 5
|
33
|
-
rake("environment
|
26
|
+
rake("environment sunspot:reindex", env: environment)
|
34
27
|
rake("sunspot:solr:stop", env: environment)
|
35
28
|
end
|
36
29
|
end
|
@@ -5,7 +5,6 @@ class EnjuLeaf::SetupGenerator < Rails::Generators::Base
|
|
5
5
|
def copy_setup_files
|
6
6
|
directory("db/fixtures", "db/fixtures/enju_leaf")
|
7
7
|
copy_file("Procfile", "Procfile")
|
8
|
-
copy_file("config/application.yml", "config/application.yml")
|
9
8
|
copy_file("config/resque.yml", "config/resque.yml")
|
10
9
|
copy_file("config/schedule.rb", "config/schedule.rb")
|
11
10
|
inject_into_file 'config/application.rb', after: /# config.i18n.default_locale = :de$\n/ do
|
@@ -33,6 +32,15 @@ EOS
|
|
33
32
|
end
|
34
33
|
generate("devise:install")
|
35
34
|
generate("devise", "User")
|
35
|
+
generate("sunspot_rails:install")
|
36
|
+
generate("kaminari:config")
|
37
|
+
generate("simple_form:install")
|
38
|
+
gsub_file "config/sunspot.yml",
|
39
|
+
/path: \/solr\/production/,
|
40
|
+
"path: /solr/default"
|
41
|
+
gsub_file 'config/initializers/kaminari_config.rb',
|
42
|
+
/# config.default_per_page = 25$/,
|
43
|
+
"config.default_per_page = 10"
|
36
44
|
if Rails::VERSION::MAJOR >= 4
|
37
45
|
generate("friendly_id")
|
38
46
|
gsub_file 'config/initializers/friendly_id.rb', /# config.use :finders$/, "config.use :finders"
|
@@ -40,11 +48,6 @@ EOS
|
|
40
48
|
/\/\/= require turbolinks$/,
|
41
49
|
""
|
42
50
|
end
|
43
|
-
generate("enju_biblio:setup")
|
44
|
-
generate("enju_library:setup")
|
45
|
-
rake("enju_leaf_engine:install:migrations")
|
46
|
-
rake("enju_biblio_engine:install:migrations")
|
47
|
-
rake("enju_library_engine:install:migrations")
|
48
51
|
gsub_file 'config/routes.rb', /devise_for :users$/, "devise_for :users, path: 'accounts'"
|
49
52
|
gsub_file 'config/initializers/devise.rb', '# config.email_regexp = /\A[^@]+@[^@]+\z/', 'config.email_regexp = /\A([\w\.%\+\-]+)@([\w\-]+\.)+([\w]{2,})\Z/i'
|
50
53
|
gsub_file 'config/initializers/devise.rb', '# config.authentication_keys = [ :email ]', 'config.authentication_keys = [ :username ]'
|
@@ -58,6 +61,7 @@ EOS
|
|
58
61
|
:lockable, :lock_strategy => :none, :unlock_strategy => :none
|
59
62
|
enju_leaf_user_model
|
60
63
|
EOS
|
64
|
+
|
61
65
|
inject_into_class "app/controllers/application_controller.rb", ApplicationController do
|
62
66
|
<<"EOS"
|
63
67
|
enju_leaf
|
@@ -66,7 +70,7 @@ EOS
|
|
66
70
|
|
67
71
|
mobylette_config do |config|
|
68
72
|
config[:skip_xhr_requests] = false
|
69
|
-
config[:skip_user_agents] =
|
73
|
+
config[:skip_user_agents] = ENV['ENJU_SKIP_MOBILE_AGENTS'].to_s.split.map{|s| s.to_sym}
|
70
74
|
end
|
71
75
|
|
72
76
|
EOS
|
@@ -82,6 +86,7 @@ EOS
|
|
82
86
|
end
|
83
87
|
EOS
|
84
88
|
end
|
89
|
+
|
85
90
|
inject_into_file "app/assets/javascripts/application.js", after: /\/\/= require jquery_ujs$\n/ do
|
86
91
|
"//= require enju_leaf\n"
|
87
92
|
end
|
@@ -94,15 +99,6 @@ require 'rack/protection'
|
|
94
99
|
use Rack::Protection, except: [:escaped_params, :json_csrf, :http_origin, :session_hijacking, :remote_token]
|
95
100
|
EOS
|
96
101
|
end
|
97
|
-
generate("sunspot_rails:install")
|
98
|
-
gsub_file "config/sunspot.yml",
|
99
|
-
/path: \/solr\/production/,
|
100
|
-
"path: /solr/default"
|
101
|
-
generate("kaminari:config")
|
102
|
-
generate("simple_form:install")
|
103
|
-
gsub_file 'config/initializers/kaminari_config.rb',
|
104
|
-
/# config.default_per_page = 25$/,
|
105
|
-
"config.default_per_page = 10"
|
106
102
|
create_file 'config/initializers/mobile.rb' do <<"EOS"
|
107
103
|
ActionController::Responder.class_eval do
|
108
104
|
alias :to_mobile :to_html
|
@@ -111,5 +107,16 @@ EOS
|
|
111
107
|
end
|
112
108
|
remove_file "public/index.html"
|
113
109
|
remove_file "app/views/layouts/application.html.erb"
|
110
|
+
gsub_file 'config/schedule.rb', /^set :environment, :development$/,
|
111
|
+
"set :environment, :#{environment}"
|
112
|
+
gsub_file 'config/environments/production.rb',
|
113
|
+
/config.serve_static_assets = false$/,
|
114
|
+
"config.serve_static_assets = true"
|
115
|
+
gsub_file 'config/environments/production.rb',
|
116
|
+
/# config.cache_store = :mem_cache_store$/,
|
117
|
+
"config.cache_store = :dalli_store, {:compress => true}"
|
118
|
+
gsub_file 'config/environments/production.rb',
|
119
|
+
/# config.assets.precompile \+= %w\( search.js \)$/,
|
120
|
+
"config.assets.precompile += %w( mobile.js mobile.css print.css )"
|
114
121
|
end
|
115
122
|
end
|
@@ -11,14 +11,14 @@ describe MyAccountsController do
|
|
11
11
|
end
|
12
12
|
|
13
13
|
it "assigns the requested user as @user" do
|
14
|
-
get :show, :
|
14
|
+
get :show, id: 'admin'
|
15
15
|
expect(response).to be_success
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
19
|
describe "When not logged in" do
|
20
20
|
it "assigns the requested user as @user" do
|
21
|
-
get :show, :
|
21
|
+
get :show, id: 'admin'
|
22
22
|
expect(assigns(:user)).to be_nil
|
23
23
|
expect(response).to redirect_to(new_user_session_url)
|
24
24
|
end
|
@@ -80,8 +80,8 @@ describe MyAccountsController do
|
|
80
80
|
|
81
81
|
describe "PUT update" do
|
82
82
|
before(:each) do
|
83
|
-
@attrs = {:user_attributes => {:
|
84
|
-
@invalid_attrs = {:user_attributes => {:
|
83
|
+
@attrs = {:user_attributes => {email: 'newaddress@example.jp', :current_password => 'password'}, :locale => 'en'}
|
84
|
+
@invalid_attrs = {:user_attributes => {username: ''}, user_number: '日本語'}
|
85
85
|
@invalid_passwd_attrs = {:user_attributes => {:current_password=> ''}}
|
86
86
|
end
|
87
87
|
|
@@ -124,11 +124,12 @@ describe MyAccountsController do
|
|
124
124
|
expect(response).to render_template("edit")
|
125
125
|
end
|
126
126
|
end
|
127
|
+
|
127
128
|
describe "with invalid password params" do
|
128
129
|
it "assigns the requested user as @user" do
|
129
130
|
put :update, profile: @invalid_passwd_attrs
|
130
|
-
|
131
|
-
|
131
|
+
expect(assigns(:profile).errors).not_to be_blank
|
132
|
+
end
|
132
133
|
end
|
133
134
|
end
|
134
135
|
|
@@ -5,9 +5,9 @@ describe ProfilesController do
|
|
5
5
|
fixtures :all
|
6
6
|
|
7
7
|
describe "GET index", :solr => true do
|
8
|
-
|
9
|
-
|
10
|
-
|
8
|
+
before do
|
9
|
+
Profile.reindex
|
10
|
+
end
|
11
11
|
|
12
12
|
describe "When logged in as Administrator" do
|
13
13
|
login_fixture_admin
|
@@ -202,24 +202,24 @@ describe ProfilesController do
|
|
202
202
|
|
203
203
|
describe "with valid params" do
|
204
204
|
it "assigns a newly created user as @profile" do
|
205
|
-
post :create, :
|
205
|
+
post :create, profile: @attrs
|
206
206
|
assigns(:profile).should be_valid
|
207
207
|
end
|
208
208
|
|
209
209
|
it "redirects to the created user" do
|
210
|
-
post :create, :
|
210
|
+
post :create, profile: @attrs
|
211
211
|
response.should redirect_to(profile_url(assigns(:profile)))
|
212
212
|
end
|
213
213
|
end
|
214
214
|
|
215
215
|
describe "with invalid params" do
|
216
216
|
it "assigns a newly created but unsaved user as @profile" do
|
217
|
-
post :create, :
|
217
|
+
post :create, profile: @invalid_attrs
|
218
218
|
assigns(:profile).should_not be_valid
|
219
219
|
end
|
220
220
|
|
221
221
|
it "re-renders the 'new' template" do
|
222
|
-
post :create, :
|
222
|
+
post :create, profile: @invalid_attrs
|
223
223
|
response.should render_template("new")
|
224
224
|
end
|
225
225
|
end
|
@@ -230,24 +230,24 @@ describe ProfilesController do
|
|
230
230
|
|
231
231
|
describe "with valid params" do
|
232
232
|
it "assigns a newly created user as @profile" do
|
233
|
-
post :create, :
|
233
|
+
post :create, profile: @attrs
|
234
234
|
assigns(:profile).should be_valid
|
235
235
|
end
|
236
236
|
|
237
237
|
it "redirects to the created user" do
|
238
|
-
post :create, :
|
238
|
+
post :create, profile: @attrs
|
239
239
|
response.should redirect_to(profile_url(assigns(:profile)))
|
240
240
|
end
|
241
241
|
end
|
242
242
|
|
243
243
|
describe "with invalid params" do
|
244
244
|
it "assigns a newly created but unsaved user as @profile" do
|
245
|
-
post :create, :
|
245
|
+
post :create, profile: @invalid_attrs
|
246
246
|
assigns(:profile).should_not be_valid
|
247
247
|
end
|
248
248
|
|
249
249
|
it "re-renders the 'new' template" do
|
250
|
-
post :create, :
|
250
|
+
post :create, profile: @invalid_attrs
|
251
251
|
response.should render_template("new")
|
252
252
|
end
|
253
253
|
end
|
@@ -311,7 +311,7 @@ describe ProfilesController do
|
|
311
311
|
end
|
312
312
|
|
313
313
|
it "should update other user's role" do
|
314
|
-
put :update, id: profiles(:user1).id, profile: {:user_attributes => {:user_has_role_attributes => {:role_id => 4}, :email => profiles(:user1).user.email, :locale => 'en', :
|
314
|
+
put :update, id: profiles(:user1).id, profile: {:user_attributes => {:user_has_role_attributes => {:role_id => 4}, :email => profiles(:user1).user.email, :locale => 'en', id: profiles(:user1).user.id}}
|
315
315
|
response.should redirect_to profile_url(assigns(:profile))
|
316
316
|
assigns(:profile).reload
|
317
317
|
assigns(:profile).user.role.should eq Role.where(name: 'Administrator').first
|
@@ -45,7 +45,7 @@ describe RolesController do
|
|
45
45
|
|
46
46
|
it "assigns the requested role as @role" do
|
47
47
|
role = Role.find(1)
|
48
|
-
get :show, :
|
48
|
+
get :show, id: role.id
|
49
49
|
expect(assigns(:role)).to eq(role)
|
50
50
|
end
|
51
51
|
end
|
@@ -53,7 +53,7 @@ describe RolesController do
|
|
53
53
|
describe "When not logged in" do
|
54
54
|
it "assigns the requested role as @role" do
|
55
55
|
role = Role.find(1)
|
56
|
-
get :show, :
|
56
|
+
get :show, id: role.id
|
57
57
|
expect(assigns(:role)).to eq(role)
|
58
58
|
end
|
59
59
|
end
|
@@ -65,7 +65,7 @@ describe RolesController do
|
|
65
65
|
|
66
66
|
it "assigns the requested role as @role" do
|
67
67
|
role = Role.find(1)
|
68
|
-
get :edit, :
|
68
|
+
get :edit, id: role.id
|
69
69
|
expect(assigns(:role)).to eq(role)
|
70
70
|
end
|
71
71
|
end
|
@@ -73,7 +73,7 @@ describe RolesController do
|
|
73
73
|
describe "When not logged in" do
|
74
74
|
it "should not assign the requested role as @role" do
|
75
75
|
role = Role.find(1)
|
76
|
-
get :edit, :
|
76
|
+
get :edit, id: role.id
|
77
77
|
expect(response).to redirect_to(new_user_session_url)
|
78
78
|
end
|
79
79
|
end
|
@@ -83,7 +83,7 @@ describe RolesController do
|
|
83
83
|
before(:each) do
|
84
84
|
@role = Role.find(1)
|
85
85
|
@attrs = {:display_name => 'guest user'}
|
86
|
-
@invalid_attrs = {:
|
86
|
+
@invalid_attrs = {name: ''}
|
87
87
|
end
|
88
88
|
|
89
89
|
describe "When logged in as Administrator" do
|
@@ -91,23 +91,23 @@ describe RolesController do
|
|
91
91
|
|
92
92
|
describe "with valid params" do
|
93
93
|
it "updates the requested role" do
|
94
|
-
put :update, :
|
94
|
+
put :update, id: @role.id, :role => @attrs
|
95
95
|
end
|
96
96
|
|
97
97
|
it "assigns the requested role as @role" do
|
98
|
-
put :update, :
|
98
|
+
put :update, id: @role.id, :role => @attrs
|
99
99
|
expect(assigns(:role)).to eq(@role)
|
100
100
|
end
|
101
101
|
|
102
102
|
it "moves its position when specified" do
|
103
|
-
put :update, :
|
103
|
+
put :update, id: @role.id, :role => @attrs, move: 'lower'
|
104
104
|
expect(response).to redirect_to(roles_url)
|
105
105
|
end
|
106
106
|
end
|
107
107
|
|
108
108
|
describe "with invalid params" do
|
109
109
|
it "assigns the requested role as @role" do
|
110
|
-
put :update, :
|
110
|
+
put :update, id: @role.id, :role => @invalid_attrs
|
111
111
|
expect(response).to render_template("edit")
|
112
112
|
end
|
113
113
|
end
|
@@ -116,18 +116,18 @@ describe RolesController do
|
|
116
116
|
describe "When not logged in" do
|
117
117
|
describe "with valid params" do
|
118
118
|
it "updates the requested role" do
|
119
|
-
put :update, :
|
119
|
+
put :update, id: @role.id, :role => @attrs
|
120
120
|
end
|
121
121
|
|
122
122
|
it "should be forbidden" do
|
123
|
-
put :update, :
|
123
|
+
put :update, id: @role.id, :role => @attrs
|
124
124
|
expect(response).to redirect_to(new_user_session_url)
|
125
125
|
end
|
126
126
|
end
|
127
127
|
|
128
128
|
describe "with invalid params" do
|
129
129
|
it "assigns the requested role as @role" do
|
130
|
-
put :update, :
|
130
|
+
put :update, id: @role.id, :role => @invalid_attrs
|
131
131
|
expect(response).to redirect_to(new_user_session_url)
|
132
132
|
end
|
133
133
|
end
|