diff --git a/app/controllers/registrations_controller.rb b/app/controllers/registrations_controller.rb
index 78ecb7c..540d199 100644
--- a/app/controllers/registrations_controller.rb
+++ b/app/controllers/registrations_controller.rb
@@ -2,6 +2,7 @@
class RegistrationsController < Devise::RegistrationsController
def edit
+ @user.create_default_preferences
@languages = Language.all.order("name")
@orgs = Org.where(parent_id: nil).order("name")
@other_organisations = Org.where(parent_id: nil, is_other: true).pluck(:id)
diff --git a/app/models/user.rb b/app/models/user.rb
index 9103a5e..08ed05b 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -283,8 +283,10 @@
##
# User Notification Preferences
def create_default_preferences
- # Set the default preferences if this is a new user
- self.prefs = self.class.create_default_preferences if self.id.nil?
+ # Set the default preferences for a new user or if existing user if null
+ if self.id.nil? || self.prefs == {}
+ self.prefs = self.class.create_default_preferences
+ end
end
def self.create_default_preferences
diff --git a/app/views/devise/registrations/edit.html.erb b/app/views/devise/registrations/edit.html.erb
index 8762484..8cb10ea 100644
--- a/app/views/devise/registrations/edit.html.erb
+++ b/app/views/devise/registrations/edit.html.erb
@@ -34,7 +34,6 @@
-
diff --git a/lib/assets/stylesheets/roadmap-form.scss b/lib/assets/stylesheets/roadmap-form.scss
index 9f717a7..e457bda 100644
--- a/lib/assets/stylesheets/roadmap-form.scss
+++ b/lib/assets/stylesheets/roadmap-form.scss
@@ -146,7 +146,7 @@
color: $reverse-text;
padding: 4px 12px;
font-size: 14px;
- margin-top: 15px;
+ margin: 5px 10px;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
diff --git a/lib/assets/stylesheets/roadmap-tabs.scss b/lib/assets/stylesheets/roadmap-tabs.scss
index 99cbab2..0b386fd 100644
--- a/lib/assets/stylesheets/roadmap-tabs.scss
+++ b/lib/assets/stylesheets/roadmap-tabs.scss
@@ -47,11 +47,11 @@
}
.tabbed-area div.tab-panel {
padding: 10px 10px;
- min-height: 300px;
+ min-height: 400px;
position: absolute;
top: -1px;
left: 0;
- width: inherit;
+ width: 100%;
border: 1px solid $primary-color;
border-top-left-radius: 0;
border-top-right-radius: 5px;
diff --git a/lib/assets/stylesheets/roadmap.scss b/lib/assets/stylesheets/roadmap.scss
index 22b9763..be91597 100644
--- a/lib/assets/stylesheets/roadmap.scss
+++ b/lib/assets/stylesheets/roadmap.scss
@@ -59,7 +59,7 @@
div.header_left {
width: auto;
-
+
.home_logo {
margin: 0 10px 0 0;
}
@@ -110,7 +110,7 @@
padding: 8px 20px;
border-radius: 5px;
vertical-align: middle;
-
+
span {
padding-left: 30px;
}
@@ -156,7 +156,6 @@
}
}
-
.checkbox-label {
display: inline-block;
font-size: 1em;
diff --git a/test/unit/user_test.rb b/test/unit/user_test.rb
index 2a1947a..a0718b3 100644
--- a/test/unit/user_test.rb
+++ b/test/unit/user_test.rb
@@ -4,8 +4,8 @@
def setup
scaffold_plan
-
- @user = User.create(email: 'me@example.edu',
+
+ @user = User.create(email: 'me@example.edu',
password: 'password',
password_confirmation: 'password',
firstname: 'Test',
@@ -25,7 +25,7 @@
assert_not User.new(firstname: 'test', surname: 'user').valid?
assert_not User.new(firstname: 'test', surname: 'user', password: 'password').valid?
assert_not User.new(firstname: 'test', surname: 'user', email: 'me@example.org').valid?
-
+
# Ensure the bar minimum and complete versions are valid
a = User.new(email: 'me_testing@example.edu', password: 'password')
assert a.valid?, "expected 'email' and 'password' to be enough to create a User - #{a.errors.map{|f, m| f.to_s + ' ' + m}.join(', ')}"
@@ -43,7 +43,7 @@
assert_not User.new(email: 'me@example.org', password: 'pass12').valid?
assert_not User.new(email: 'me@example.org', password: 'Pass12').valid?
assert_not User.new(email: 'me@example.org', password: 'Pass12*').valid?
-
+
assert User.new(email: 'me@example.org', password: 'Password12*').valid?
assert User.new(email: 'me@example.org', password: 'passwords').valid?
assert User.new(email: 'me@example.org', password: 'Password').valid?
@@ -51,13 +51,13 @@
# ---------------------------------------------------
test "name returns the correct value" do
- # Name should return 'First Last' if we do not specify email
+ # Name should return 'First Last' if we do not specify email
assert @user.name(false).include?(@user.firstname), "expected the first name to be included when specifying non-email"
assert @user.name(false).include?(@user.surname), "expected the last name to be included when specifying non-email"
-
+
# Should return email if we do not pass in a variable
assert_equal @user.email, @user.name, "expected the email by default"
-
+
# Name should return the email if no first and last are present
@user.firstname = nil
@user.surname = nil
@@ -67,69 +67,69 @@
# ---------------------------------------------------
test "only accepts valid email addresses" do
assert @user.valid?
-
+
@user.email = 'testing'
assert_not @user.valid?
@user.email = 'testing.tester.org'
assert_not @user.valid?
@user.email = 'testing@tester'
assert_not @user.valid?
-
+
@user.email = 'testing@tester.org'
assert @user.valid?
end
-
+
# ---------------------------------------------------
test "api token is removed after call to remove_token" do
@user.api_token = 'ABCDEFGHIJKLMNOP'
@user.save!
assert_equal 'ABCDEFGHIJKLMNOP', @user.reload.api_token, "expected the api_token to have been initialized"
-
+
@user.remove_token!
assert_equal '', @user.reload.api_token, "expected the api_token to have been removed"
end
-
+
# ---------------------------------------------------
test "api token gets kept or created" do
@user.api_token = 'ABCDEFGHIJKLMNOP'
@user.save!
assert_equal 'ABCDEFGHIJKLMNOP', @user.reload.api_token, "expected the api_token to have been initialized"
-
+
@user.keep_or_generate_token!
assert_equal 'ABCDEFGHIJKLMNOP', @user.reload.api_token, "expected the api_token to have been kept"
@user.remove_token!
assert_equal '', @user.reload.api_token, "expected the api_token to have been removed"
-
+
@user.keep_or_generate_token!
assert_not_equal '', @user.reload.api_token, "expected the api_token to have been generated"
end
-
+
# ---------------------------------------------------
test "responds to all of the authentication options" do
super_admins = User.joins(:perms).where('perms.name = ?', 'add_organisations').to_a
org_admins = User.joins(:perms).where('perms.name = ?', 'modify_templates').to_a
users = User.includes(:perms).where(perms: {id: nil}).to_a
-
+
# remove all of the users who also have super_admin privileges
org_admins = org_admins.delete_if{|u| super_admins.include?(u) }
admin_methods = [:can_add_orgs?, :can_change_org?, :can_grant_api_to_orgs?]
-
- org_admin_methods = [:can_grant_permissions?, :can_modify_templates?,
+
+ org_admin_methods = [:can_grant_permissions?, :can_modify_templates?,
:can_modify_guidance?, :can_use_api?, :can_modify_org_details?]
-
+
[:can_super_admin?, :can_org_admin?].each do |auth|
assert_respond_to super_admins.first, auth, "expected User to respond to #{auth}"
end
-
+
# Super Admin - permission checks
admin_methods.each do |auth|
#assert super_admins.first.send(auth), "expected that Super Admin #{auth}"
assert_not org_admins.first.send(auth), "did NOT expect that Organisation Admin #{auth}"
assert_not @user.send(auth), "did NOT expect that User #{auth}"
end
-
+
# Organisational Admin - permission checks
org_admin_methods.each do |auth|
#assert super_admins.first.send(auth), "expected that the Super Admin #{auth}"
@@ -137,29 +137,29 @@
assert_not @user.send(auth), "did NOT expect that User #{auth}"
end
end
-
+
# ---------------------------------------------------
test "can only have one identifier per IdentifierScheme" do
@scheme = IdentifierScheme.first
-
+
count = @user.user_identifiers.count
@user.user_identifiers << UserIdentifier.new(identifier_scheme: @scheme, identifier: 'abc')
@user.save!
@user.reload
-
+
assert_equal (count + 1), @user.user_identifiers.count, "Expected the initial identifier to be saved"
-
+
@user.user_identifiers << UserIdentifier.new(identifier_scheme: @scheme, identifier: 'abc')
assert_not @user.valid?, "Expected to NOT be able to add more than one identifier for the same scheme"
assert_equal (count + 1), @user.user_identifiers.count, "Expected the initial identifier to be saved"
end
-
+
# ---------------------------------------------------
test "can find a user via an OAuth response" do
scheme = IdentifierScheme.create!(name: 'tester', active: true)
@user.user_identifiers << UserIdentifier.new(identifier_scheme: scheme, identifier: '12345')
@user.save!
-
+
class Auth
def provider
"tester"
@@ -168,9 +168,9 @@
"12345"
end
end
-
+
assert_equal @user, User.from_omniauth(Auth.new)
-
+
class UnknownAuth
def provider
"unknown"
@@ -179,12 +179,12 @@
"12345"
end
end
-
+
assert_raise "'Unknown OAuth provider: unknown" do
User.from_omniauth(UnknownAuth.new)
end
end
-
+
# ---------------------------------------------------
test "Plans query filter is working properly" do
3.times do |i|
@@ -196,28 +196,28 @@
plan = @user.plans.filter("2").first
assert_equal "My test 2", plan.title, "Expected the plans filter to search the title"
end
-
+
# ---------------------------------------------------
test "Returns the appropriate identifier for the specified scheme" do
3.times do |i|
scheme = IdentifierScheme.create!({name: "test-#{i}", active: true})
-
+
@user.user_identifiers << UserIdentifier.new(identifier_scheme: scheme, identifier: i.to_s)
end
@user.save!
-
+
3.times do |i|
scheme = IdentifierScheme.find_by(name: "test-#{i}")
-
+
assert_equal i.to_s, @user.identifier_for(scheme).identifier, "expected the identifier for #{scheme.name} to be '#{i.to_s}'"
end
end
-
+
# ---------------------------------------------------
test "can_super_admin is properly set" do
perms = Perm.where('name IN (?)', ['add_organisations', 'change_org_affiliation', 'grant_api_to_orgs'])
user = User.create!(email: 'tester@example.edu', password: 'password')
-
+
assert_not user.can_super_admin?, "expected a user with no permissions to NOT be a super_admin"
perms.each do |p|
@@ -225,23 +225,23 @@
user.perms.delete(last) unless last.nil?
user.perms << p
user.save!
-
+
assert user.can_super_admin?, "expected the addition of the #{p.name} perm to enable the user to become a super_admin"
end
-
+
user.perms = []
user.save!
-
+
user.perms = perms
user.save!
assert user.can_super_admin?, "expected the addition of all the super_admin perms to allow the user to be a super_admin"
end
-
+
# ---------------------------------------------------
test "can_org_admin is properly set" do
perms = Perm.where('name IN (?)', ['grant_permissions', 'modify_templates', 'modify_guidance', 'change_org_details'])
user = User.create!(email: 'tester@example.edu', password: 'password')
-
+
assert_not user.can_org_admin?, "expected a user with no permissions to NOT be a org_admin"
perms.each do |p|
@@ -249,18 +249,18 @@
user.perms.delete(last) unless last.nil?
user.perms << p
user.save!
-
+
assert user.can_org_admin?, "expected the addition of the #{p.name} perm to enable the user to become a org_admin"
end
-
+
user.perms = []
user.save!
-
+
user.perms = perms
user.save!
assert user.can_org_admin?, "expected the addition of all the super_admin perms to allow the user to be a org_admin"
end
-
+
# ---------------------------------------------------
test "can CRUD" do
usr = User.create(email: 'test@testing.org', password: 'testing1234')
@@ -270,51 +270,51 @@
usr.save!
usr.reload
assert_equal 'Tester', usr.firstname, "Was expecting to be able to update the firstname of the User!"
-
+
assert usr.destroy!, "Was unable to delete the User!"
end
-
+
# ---------------------------------------------------
test "can manage has_many relationship with Perms" do
perm = Perm.new(name: 'Added through test')
verify_has_many_relationship(@user, perm, @user.perms.count)
end
-
+
# ---------------------------------------------------
test "can manage has_many relationship with UserIdentifiers" do
id = UserIdentifier.new(identifier_scheme: IdentifierScheme.first, identifier: 'tester')
verify_has_many_relationship(@user, id, @user.user_identifiers.count)
end
-
+
# ---------------------------------------------------
test "can manage has_many relationship with Roles" do
role = Role.new(plan: @plan, access: 1)
verify_has_many_relationship(@user, role, @user.roles.count)
- end
-
+ end
+
# ---------------------------------------------------
test "can manage has_many relationship with Answers" do
- answer = Answer.new(plan: @plan,
- question: @plan.template.phases.first.sections.first.questions.first,
+ answer = Answer.new(plan: @plan,
+ question: @plan.template.phases.first.sections.first.questions.first,
text: 'Testing')
verify_has_many_relationship(@user, answer, @user.answers.count)
end
-
+
# ---------------------------------------------------
test "can manage has_many relationship with Notes" do
- answer = Answer.create(plan: @plan,
- question: @plan.template.phases.first.sections.first.questions.first,
+ answer = Answer.create(plan: @plan,
+ question: @plan.template.phases.first.sections.first.questions.first,
text: 'Testing')
note = Note.new(answer: answer, text: 'Testing')
verify_has_many_relationship(@user, note, @user.notes.count)
end
-
+
# ---------------------------------------------------
test "can manage has_many relationship with ExportedPlans" do
plan = ExportedPlan.new(plan: @plan, format: ExportedPlan::VALID_FORMATS.last)
verify_has_many_relationship(@user, plan, @user.exported_plans.count)
end
-
+
# ---------------------------------------------------
test "can manage belongs_to relationship with Org" do
org = Org.new(name: 'Tester', abbreviation: 'TST')
@@ -327,4 +327,10 @@
verify_belongs_to_relationship(@user, language)
end
+ # ---------------------------------------------------
+ test "can create default notification preferences when user is created" do
+ user = User.create(email: 'test@testing.org', password: 'testing1234')
+ user.save
+ assert_not_nil(user.prefs)
+ end
end