diff --git a/Gemfile b/Gemfile
index 35ee76e..06b3e3f 100644
--- a/Gemfile
+++ b/Gemfile
@@ -29,10 +29,6 @@
gem 'jbuilder'
# ------------------------------------------------
-# CLONE ACTIVERECORD MODELS AND ASSOCIATIONS
-gem 'amoeba'
-
-# ------------------------------------------------
# SLUGS/PERMALINKS
gem 'friendly_id'
diff --git a/Gemfile.lock b/Gemfile.lock
index 8359a7c..d430a3c 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -64,8 +64,6 @@
thread_safe (~> 0.3, >= 0.3.4)
tzinfo (~> 1.1)
addressable (2.4.0)
- amoeba (3.0.0)
- activerecord (>= 3.2.6)
ansi (1.5.0)
arbre (1.1.1)
activesupport (>= 3.0.0)
@@ -360,7 +358,6 @@
DEPENDENCIES
activeadmin!
- amoeba
better_errors
binding_of_caller
byebug
diff --git a/app/controllers/answers_controller.rb b/app/controllers/answers_controller.rb
index f85c4dd..b469272 100644
--- a/app/controllers/answers_controller.rb
+++ b/app/controllers/answers_controller.rb
@@ -3,8 +3,7 @@
respond_to :html
##
- # POST /answers
-
+ # PUT/PATCH /[:locale]/answer/[:id]
def update
# create a new answer based off the passed params
logger.debug("RAY: update params=")
diff --git a/app/controllers/templates_controller.rb b/app/controllers/templates_controller.rb
index 7ce8920..7de0789 100644
--- a/app/controllers/templates_controller.rb
+++ b/app/controllers/templates_controller.rb
@@ -9,9 +9,10 @@
# GET /dmptemplates
def admin_index
authorize Template
- #institutional templates
+ # institutional templates
all_versions_own_templates = Template.where(org_id: current_user.org_id, customization_of: nil).order(version: :desc)
current_templates = {}
+ # take most recent version of each template
all_versions_own_templates.each do |temp|
if current_templates[temp.dmptemplate_id].nil?
current_templates[temp.dmptemplate_id] = temp
@@ -27,6 +28,9 @@
def admin_template
@template = Template.find(params[:id])
authorize @template
+ if @template.published
+ # create a new template version
+ end
end
@@ -36,7 +40,7 @@
authorize @template
@template.description = params["template-desc"]
if @template.update_attributes(params[:template])
- redirect_to admin_template_template_path(params[:template]), notice: I18n.t('org_admin.templates.updated_message')
+ redirect_to admin_index_template_path(), notice: I18n.t('org_admin.templates.updated_message')
else
render action: "edit"
end
diff --git a/app/controllers/users/omniauth_callbacks_controller.rb b/app/controllers/users/omniauth_callbacks_controller.rb
index 9b65b77..74337c0 100644
--- a/app/controllers/users/omniauth_callbacks_controller.rb
+++ b/app/controllers/users/omniauth_callbacks_controller.rb
@@ -7,7 +7,7 @@
handle_omniauth(scheme)
end
end
-
+
##
# Processes callbacks from an omniauth provider and directs the user to
# the appropriate page:
@@ -19,6 +19,9 @@
# @scheme [IdentifierScheme] The IdentifierScheme for the provider
# -------------------------------------------------------------
def handle_omniauth(scheme)
+
+puts "now weez handlin it #{scheme}"
+
user = User.from_omniauth(request.env["omniauth.auth"].nil? ? request.env : request.env["omniauth.auth"])
# If the user isn't logged in
diff --git a/app/models/phase.rb b/app/models/phase.rb
index 49029f8..eae90f1 100644
--- a/app/models/phase.rb
+++ b/app/models/phase.rb
@@ -86,4 +86,20 @@
end
return has_section
end
+
+ ##
+ # deep copy the given phase and all it's associations
+ #
+ # @params [Phase] phase to be deep copied
+ # @return [Phase] the saved, copied phase
+ def self.deep_copy(phase)
+ phase_copy = phase.dup
+ phase_copy.save!
+ phase.sections.each do |section|
+ section_copy = Section.deep_copy(section)
+ section_copy.phase_id = phase_copy.id
+ section_copy.save!
+ end
+ return phase_copy
+ end
end
diff --git a/app/models/plan.rb b/app/models/plan.rb
index bf970ee..11dcf68 100644
--- a/app/models/plan.rb
+++ b/app/models/plan.rb
@@ -27,7 +27,7 @@
:exported_plans, :project, :title, :template, :grant_number,
:identifier, :principal_investigator, :principal_investigator_identifier,
:description, :data_contact, :funder_name, :visibility, :exported_plans,
- :roles, :users, :as => [:default, :admin]
+ :roles, :users, :org, :as => [:default, :admin]
accepts_nested_attributes_for :roles
# public is a Ruby keyword so using publicly
diff --git a/app/models/question.rb b/app/models/question.rb
index 5493b79..c2631a5 100644
--- a/app/models/question.rb
+++ b/app/models/question.rb
@@ -44,15 +44,29 @@
"#{text}"
end
-# TODO: Commented this amoeba cloning gem definition out to see if its even used. The
-# amoeba documentations uses [object].amoeba_dup to clone the object, but that
-# command does not exist in the codebase
-
-# amoeba do
-# include_association :options
-# include_association :suggested_answers
-# clone [:themes]
-# end
+ ##
+ # deep copy the given question and all it's associations
+ #
+ # @params [Question] question to be deep copied
+ # @return [Question] the saved, copied question
+ def self.deep_copy(question)
+ question_copy = question.dup
+ question_copy.save!
+ question.question_options.each do |question_option|
+ question_option_copy = QuestionOption.deep_copy(question_option)
+ question_option_copy.question_id = question_copy.id
+ question_option_copy.save!
+ end
+ question.suggested_answers.each do |suggested_answer|
+ suggested_answer_copy = SuggestedAnswer.deep_copy(suggested_answer)
+ suggested_answer_copy.quesion_id = question_copy.id
+ suggested_answer_copy.save!
+ end
+ question.themes.each do |theme|
+ question_copy.themes << theme
+ end
+ return question_copy
+ end
##
# guidance for org
diff --git a/app/models/question_option.rb b/app/models/question_option.rb
index 1a079d0..11552b0 100644
--- a/app/models/question_option.rb
+++ b/app/models/question_option.rb
@@ -9,6 +9,17 @@
# -relies on protected_attributes gem as syntax depricated in rails 4.2
attr_accessible :text, :question_id, :is_default, :number, :question,
:as => [:default, :admin]
-
+
validates :text, :question, :number, presence: true
+
+ ##
+ # deep copy the given question_option and all it's associations
+ #
+ # @params [QuestionOption] question_option to be deep copied
+ # @return [QuestionOption] the saved, copied question_option
+ def self.deep_copy(question_option)
+ question_option_copy = question_option.dup
+ question_option_copy.save!
+ return question_option_copy
+ end
end
diff --git a/app/models/section.rb b/app/models/section.rb
index 4b484ab..710e8c7 100644
--- a/app/models/section.rb
+++ b/app/models/section.rb
@@ -24,11 +24,20 @@
"#{title}"
end
-# TODO: Commented this amoeba cloning gem definition out to see if its even used. The
-# amoeba documentations uses [object].amoeba_dup to clone the object, but that
-# command does not exist in the codebase
-# amoeba do
-# include_association :questions
-# end
+ ##
+ # deep copy of the given section and all it's associations
+ #
+ # @params [Section] section to be deep copied
+ # @return [Section] the saved, copied section
+ def self.deep_copy(section)
+ section_copy = section.dup
+ section_copy.save!
+ section.questions.each do |question|
+ question_copy = Question.deep_copy(question)
+ question_copy.section_id = section_copy.id
+ question_copy.save!
+ end
+ return section_copy
+ end
end
diff --git a/app/models/suggested_answer.rb b/app/models/suggested_answer.rb
index f3aaaf8..8f427c6 100644
--- a/app/models/suggested_answer.rb
+++ b/app/models/suggested_answer.rb
@@ -28,4 +28,15 @@
"#{text}"
end
+
+ ##
+ # deep copy the given question_option and all it's associations
+ #
+ # @params [QuestionOption] question_option to be deep copied
+ # @return [QuestionOption] the saved, copied question_option
+ def self.deep_copy(suggested_answer)
+ suggested_answer_copy = suggested_answer.dup
+ suggested_answer_copy.save!
+ return suggested_answer_copy
+ end
end
\ No newline at end of file
diff --git a/app/models/template.rb b/app/models/template.rb
index cc8912c..87d79df 100644
--- a/app/models/template.rb
+++ b/app/models/template.rb
@@ -31,6 +31,21 @@
# What do they do? do they do it efficiently, and do we need them?
+ ##
+ # deep copy the given template and all of it's associations
+ #
+ # @params [Template] template to be deep copied
+ # @return [Template] saved copied template
+ def self.deep_copy(template)
+ template_copy = template.dup
+ template_copy.save!
+ template.phases.each do |phase|
+ phase_copy = Phase.deep_copy(phase)
+ phase_copy.template_id = template_copy.id
+ phase_copy.save!
+ end
+ return template_copy
+ end
##
# takes a type or organisation and returns all published templates from
diff --git a/app/models/user.rb b/app/models/user.rb
index 52672c4..91355df 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -6,8 +6,9 @@
# Include default devise modules. Others available are:
# :token_authenticatable, :confirmable,
# :lockable, :timeoutable and :omniauthable
- devise :invitable, :database_authenticatable, :registerable, :recoverable, :rememberable,
- :trackable, :validatable, :confirmable, :omniauthable, :omniauth_providers => [:shibboleth]
+ devise :invitable, :database_authenticatable, :registerable, :recoverable,
+ :rememberable, :trackable, :validatable, :confirmable, :omniauthable,
+ :omniauth_providers => [:shibboleth, :orcid]
##
# Associations
@@ -40,11 +41,13 @@
# Possibly needed for active_admin
# -relies on protected_attributes gem as syntax depricated in rails 4.2
accepts_nested_attributes_for :roles
- attr_accessible :password_confirmation, :encrypted_password, :remember_me, :id, :email,
- :firstname, :last_login,:login_count, :orcid_id, :password, :shibboleth_id,
- :user_status_id, :surname, :user_type_id, :org_id, :skip_invitation,
- :other_organisation, :accept_terms, :role_ids, :dmponline3, :api_token,
- :organisation, :language, :language_id, :org, :perms, :confirmed_at
+ attr_accessible :password_confirmation, :encrypted_password, :remember_me,
+ :id, :email, :firstname, :last_login,:login_count, :orcid_id,
+ :password, :shibboleth_id, :user_status_id, :surname,
+ :user_type_id, :org_id, :skip_invitation, :other_organisation,
+ :accept_terms, :role_ids, :dmponline3, :api_token,
+ :organisation, :language, :language_id, :org, :perms,
+ :confirmed_at, :org_id
validates :email, email: true, allow_nil: true, uniqueness: true
diff --git a/app/views/templates/admin_index.html.erb b/app/views/templates/admin_index.html.erb
index 5435712..027aa65 100644
--- a/app/views/templates/admin_index.html.erb
+++ b/app/views/templates/admin_index.html.erb
@@ -44,7 +44,19 @@
<%= raw org_template.description.truncate(90, omission: t('helpers.truncate_continued')) %>
- <%= org_template.published %>
+ <% #Yes if published version exists, Yes[Unpublished changes] if newer version modified, No otherwise%>
+ <% if org_template.published %>
+ <%= "Yes" %>
+ <% elsif org_template.version > 0 && Template.where(dmptemplate_id: org_template.dmptemplate_id, published: true).present? %>
+ <% #there is a published version, but this version is not %>
+ <% if org_template.created_at < org_template.updated_at %>
+ <%= "Yes [Unpublished Changes]" %>
+ <% else %>
+ <%= "Yes" %>
+ <% end %>
+ <% else %>
+ <%= "No" %>
+ <% end %>
|
<% last_temp_updated = org_template.updated_at %>
@@ -61,11 +73,11 @@
<%= link_to t('helpers.history'), admin_template_history_template_path(id: org_template.id), class: "dmp_table_link" %>
|
- <%end%>
+ <% end %>
-<%end%>
+<% end %>
diff --git a/config/initializers/devise.rb b/config/initializers/devise.rb
index 0f64f83..4dc0f0c 100644
--- a/config/initializers/devise.rb
+++ b/config/initializers/devise.rb
@@ -265,6 +265,16 @@
# so you need to do it manually. For the users scope, it would be:
# config.omniauth_path_prefix = '/my_engine/users/auth'
+ config.omniauth :orcid, 'APP-T96TCS5F64T5EB2O',
+ '8def5f5c-25f3-4faf-9bb9-0740cde89daa', {"scope": "/authenticate"}
+ # config.omniauth :orcid, 'APP-Z80XR6IBPK2D4DWN', '92e159d6-5947-4c1a-9b9e-44560ba9370b', {"scope": "/authenticate"} #{"scope": "/orcid-profile/read-limited"}
+
+ # config.omniauth :shibboleth, {uid_field: 'eppn',
+ # info_fields: {email: 'mail', name: 'cn', last_name: 'sn'},
+ # extra_fields: [:schacHomeOrganization]} #, debug: true}
+
+ config.omniauth_path_prefix = "/users/auth"
+
# Configure the system to redirect to the home page after a session timeout
config.warden do |manager|
manager.failure_app = CustomFailure
diff --git a/db/schema.rb b/db/schema.rb
index 90ab057..81d309b 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -13,391 +13,360 @@
ActiveRecord::Schema.define(version: 20170201194502) do
+ # These are extensions that must be enabled in order to support this database
+ enable_extension "plpgsql"
+
create_table "answers", force: :cascade do |t|
- t.text "text", limit: 65535
- t.integer "plan_id", limit: 4
- t.integer "user_id", limit: 4
- t.integer "question_id", limit: 4
+ t.text "text"
+ t.integer "plan_id"
+ t.integer "user_id"
+ t.integer "question_id"
t.datetime "created_at"
t.datetime "updated_at"
end
- add_index "answers", ["plan_id"], name: "fk_rails_84a6005a3e", using: :btree
- add_index "answers", ["question_id"], name: "fk_rails_3d5ed4418f", using: :btree
- add_index "answers", ["user_id"], name: "fk_rails_584be190c2", using: :btree
-
create_table "answers_question_options", id: false, force: :cascade do |t|
- t.integer "answer_id", limit: 4, null: false
- t.integer "question_option_id", limit: 4, null: false
+ t.integer "answer_id", null: false
+ t.integer "question_option_id", null: false
end
- add_index "answers_question_options", ["answer_id", "question_option_id"], name: "answer_question_option_index", using: :btree
- add_index "answers_question_options", ["question_option_id", "answer_id"], name: "question_option_answer_index", using: :btree
+ add_index "answers_question_options", ["answer_id", "question_option_id"], name: "answer_question_option_index"
+ add_index "answers_question_options", ["question_option_id", "answer_id"], name: "question_option_answer_index"
create_table "exported_plans", force: :cascade do |t|
- t.integer "plan_id", limit: 4
- t.integer "user_id", limit: 4
- t.string "format", limit: 255
- t.datetime "created_at"
- t.datetime "updated_at"
+ t.integer "plan_id"
+ t.integer "user_id"
+ t.string "format"
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
end
create_table "file_types", force: :cascade do |t|
- t.string "name", limit: 255
- t.string "icon_name", limit: 255
- t.integer "icon_size", limit: 4
- t.string "icon_location", limit: 255
- t.datetime "created_at"
- t.datetime "updated_at"
+ t.string "name"
+ t.string "icon_name"
+ t.integer "icon_size"
+ t.string "icon_location"
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
end
create_table "file_uploads", force: :cascade do |t|
- t.string "name", limit: 255
- t.string "title", limit: 255
- t.text "description", limit: 65535
- t.integer "size", limit: 4
+ t.string "name"
+ t.string "title"
+ t.text "description"
+ t.integer "size"
t.boolean "published"
- t.string "location", limit: 255
- t.integer "file_type_id", limit: 4
- t.datetime "created_at"
- t.datetime "updated_at"
+ t.string "location"
+ t.integer "file_type_id"
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
end
create_table "friendly_id_slugs", force: :cascade do |t|
- t.string "slug", limit: 255, null: false
- t.integer "sluggable_id", limit: 4, null: false
+ t.string "slug", null: false
+ t.integer "sluggable_id", null: false
t.string "sluggable_type", limit: 40
t.datetime "created_at"
end
- add_index "friendly_id_slugs", ["slug", "sluggable_type"], name: "index_friendly_id_slugs_on_slug_and_sluggable_type", unique: true, using: :btree
- add_index "friendly_id_slugs", ["sluggable_id"], name: "index_friendly_id_slugs_on_sluggable_id", using: :btree
- add_index "friendly_id_slugs", ["sluggable_type"], name: "index_friendly_id_slugs_on_sluggable_type", using: :btree
+ add_index "friendly_id_slugs", ["slug", "sluggable_type"], name: "index_friendly_id_slugs_on_slug_and_sluggable_type", unique: true
+ add_index "friendly_id_slugs", ["sluggable_id"], name: "index_friendly_id_slugs_on_sluggable_id"
+ add_index "friendly_id_slugs", ["sluggable_type"], name: "index_friendly_id_slugs_on_sluggable_type"
create_table "guidance_groups", force: :cascade do |t|
- t.string "name", limit: 255
- t.integer "org_id", limit: 4
- t.datetime "created_at"
- t.datetime "updated_at"
+ t.string "name"
+ t.integer "org_id"
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
t.boolean "optional_subset"
t.boolean "published"
end
- add_index "guidance_groups", ["org_id"], name: "fk_rails_819c1dbbc7", using: :btree
-
create_table "guidances", force: :cascade do |t|
- t.text "text", limit: 65535
- t.integer "guidance_group_id", limit: 4
- t.datetime "created_at"
- t.datetime "updated_at"
- t.integer "question_id", limit: 4
+ t.text "text"
+ t.integer "guidance_group_id"
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
+ t.integer "question_id"
t.boolean "published"
end
- add_index "guidances", ["guidance_group_id"], name: "fk_rails_20d29da787", using: :btree
-
create_table "identifier_schemes", force: :cascade do |t|
- t.string "name", limit: 255
- t.string "description", limit: 255
+ t.string "name"
+ t.string "description"
t.boolean "active"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "languages", force: :cascade do |t|
- t.string "abbreviation", limit: 255
- t.string "description", limit: 255
- t.string "name", limit: 255
+ t.string "abbreviation"
+ t.string "description"
+ t.string "name"
t.boolean "default_language"
end
create_table "notes", force: :cascade do |t|
- t.integer "user_id", limit: 4
- t.text "text", limit: 65535
+ t.integer "user_id"
+ t.text "text"
t.boolean "archived"
- t.integer "answer_id", limit: 4
- t.integer "archived_by", limit: 4
+ t.integer "answer_id"
+ t.integer "archived_by"
t.datetime "created_at"
t.datetime "updated_at"
end
- add_index "notes", ["answer_id"], name: "fk_rails_907f8d48bf", using: :btree
- add_index "notes", ["user_id"], name: "fk_rails_7f2323ad43", using: :btree
-
create_table "org_token_permissions", force: :cascade do |t|
- t.integer "org_id", limit: 4
- t.integer "token_permission_type_id", limit: 4
+ t.integer "org_id"
+ t.integer "token_permission_type_id"
t.datetime "created_at"
t.datetime "updated_at"
end
- add_index "org_token_permissions", ["org_id"], name: "fk_rails_e1db1b22c5", using: :btree
- add_index "org_token_permissions", ["token_permission_type_id"], name: "fk_rails_2aa265f538", using: :btree
-
create_table "orgs", force: :cascade do |t|
- t.string "name", limit: 255
- t.string "abbreviation", limit: 255
- t.string "target_url", limit: 255
- t.string "wayfless_entity", limit: 255
- t.datetime "created_at"
- t.datetime "updated_at"
- t.integer "parent_id", limit: 4
+ t.string "name"
+ t.string "abbreviation"
+ t.string "target_url"
+ t.string "wayfless_entity"
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
+ t.integer "parent_id"
t.boolean "is_other"
- t.string "sort_name", limit: 255
- t.text "banner_text", limit: 65535
- t.string "logo_file_name", limit: 255
- t.integer "region_id", limit: 4
- t.integer "language_id", limit: 4
- t.string "logo_uid", limit: 255
- t.string "logo_name", limit: 255
- t.string "contact_email", limit: 255
- t.integer "org_type", limit: 4, default: 0, null: false
+ t.string "sort_name"
+ t.text "banner_text"
+ t.string "logo_file_name"
+ t.integer "region_id"
+ t.integer "language_id"
+ t.string "logo_uid"
+ t.string "logo_name"
+ t.string "contact_email"
+ t.integer "org_type", default: 0, null: false
end
- add_index "orgs", ["language_id"], name: "fk_rails_5640112cab", using: :btree
- add_index "orgs", ["region_id"], name: "fk_rails_5a6adf6bab", using: :btree
-
create_table "perms", force: :cascade do |t|
- t.string "name", limit: 255
- t.datetime "created_at"
- t.datetime "updated_at"
+ t.string "name"
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
end
- add_index "perms", ["name"], name: "index_perms_on_name", using: :btree
- add_index "perms", ["name"], name: "index_roles_on_name_and_resource_type_and_resource_id", using: :btree
+ add_index "perms", ["name"], name: "index_perms_on_name"
+ add_index "perms", ["name"], name: "index_roles_on_name_and_resource_type_and_resource_id"
create_table "phases", force: :cascade do |t|
- t.string "title", limit: 255
- t.text "description", limit: 65535
- t.integer "number", limit: 4
- t.integer "template_id", limit: 4
+ t.string "title"
+ t.text "description"
+ t.integer "number"
+ t.integer "template_id"
t.datetime "created_at"
t.datetime "updated_at"
- t.string "slug", limit: 255
+ t.string "slug"
t.boolean "modifiable"
end
- add_index "phases", ["template_id"], name: "fk_rails_0f8036cb2e", using: :btree
-
- create_table "plans", force: :cascade do |t|
- t.integer "project_id", limit: 4
- t.string "title", limit: 255
- t.integer "template_id", limit: 4
- t.datetime "created_at"
- t.datetime "updated_at"
- t.string "slug", limit: 255
- t.string "grant_number", limit: 255
- t.string "identifier", limit: 255
- t.text "description", limit: 65535
- t.string "principal_investigator", limit: 255
- t.string "principal_investigator_identifier", limit: 255
- t.string "data_contact", limit: 255
- t.string "funder_name", limit: 255
- t.integer "visibility", limit: 4, default: 0, null: false
+ create_table "plan_guidance_groups", force: :cascade do |t|
+ t.integer "plan_id"
+ t.integer "guidance_group_id"
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
+ t.boolean "selected"
end
- add_index "plans", ["template_id"], name: "fk_rails_3424ca281f", using: :btree
+ add_index "plan_guidance_groups", ["guidance_group_id"], name: "index_plan_guidance_groups_on_guidance_group_id", using: :btree
+ add_index "plan_guidance_groups", ["plan_id"], name: "index_plan_guidance_groups_on_plan_id", using: :btree
- create_table "question_formats", force: :cascade do |t|
- t.string "title", limit: 255
- t.text "description", limit: 65535
+ create_table "plans", force: :cascade do |t|
+ t.integer "project_id"
+ t.string "title"
+ t.integer "template_id"
t.datetime "created_at"
t.datetime "updated_at"
- t.boolean "option_based", default: false
+ t.string "slug"
+ t.string "grant_number"
+ t.string "identifier"
+ t.text "description"
+ t.string "principal_investigator"
+ t.string "principal_investigator_identifier"
+ t.string "data_contact"
+ t.string "funder_name"
+ t.integer "visibility", default: 0, null: false
+ end
+
+ create_table "question_formats", force: :cascade do |t|
+ t.string "title"
+ t.text "description"
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
+ t.boolean "option_based", default: false
end
create_table "question_options", force: :cascade do |t|
- t.integer "question_id", limit: 4
- t.string "text", limit: 255
- t.integer "number", limit: 4
+ t.integer "question_id"
+ t.string "text"
+ t.integer "number"
t.boolean "is_default"
t.datetime "created_at"
t.datetime "updated_at"
end
- add_index "question_options", ["question_id"], name: "fk_rails_b9c5f61cf9", using: :btree
-
create_table "questions", force: :cascade do |t|
- t.text "text", limit: 65535
- t.text "default_value", limit: 65535
- t.text "guidance", limit: 65535
- t.integer "number", limit: 4
- t.integer "section_id", limit: 4
+ t.text "text"
+ t.text "default_value"
+ t.text "guidance"
+ t.integer "number"
+ t.integer "section_id"
t.datetime "created_at"
t.datetime "updated_at"
- t.integer "question_format_id", limit: 4
- t.boolean "option_comment_display", default: true
+ t.integer "question_format_id"
+ t.boolean "option_comment_display", default: true
t.boolean "modifiable"
end
- add_index "questions", ["question_format_id"], name: "fk_rails_4fbc38c8c7", using: :btree
- add_index "questions", ["section_id"], name: "fk_rails_c50eadc3e3", using: :btree
-
create_table "questions_themes", id: false, force: :cascade do |t|
- t.integer "question_id", limit: 4, null: false
- t.integer "theme_id", limit: 4, null: false
+ t.integer "question_id", null: false
+ t.integer "theme_id", null: false
end
- add_index "questions_themes", ["question_id", "theme_id"], name: "question_theme_index", using: :btree
- add_index "questions_themes", ["theme_id", "question_id"], name: "theme_question_index", using: :btree
+ add_index "questions_themes", ["question_id", "theme_id"], name: "question_theme_index"
+ add_index "questions_themes", ["theme_id", "question_id"], name: "theme_question_index"
create_table "regions", force: :cascade do |t|
- t.string "abbreviation", limit: 255
- t.string "description", limit: 255
- t.string "name", limit: 255
- t.integer "super_region_id", limit: 4
+ t.string "abbreviation"
+ t.string "description"
+ t.string "name"
+ t.integer "super_region_id"
end
create_table "roles", force: :cascade do |t|
- t.integer "user_id", limit: 4
- t.integer "plan_id", limit: 4
+ t.integer "user_id"
+ t.integer "plan_id"
t.datetime "created_at"
t.datetime "updated_at"
- t.integer "access", limit: 4, default: 0, null: false
+ t.integer "access", default: 0, null: false
end
- add_index "roles", ["plan_id"], name: "fk_rails_a1ce6c2772", using: :btree
- add_index "roles", ["user_id"], name: "fk_rails_ab35d699f0", using: :btree
-
create_table "sections", force: :cascade do |t|
- t.string "title", limit: 255
- t.text "description", limit: 65535
- t.integer "number", limit: 4
+ t.string "title"
+ t.text "description"
+ t.integer "number"
t.datetime "created_at"
t.datetime "updated_at"
t.boolean "published"
- t.integer "phase_id", limit: 4
+ t.integer "phase_id"
t.boolean "modifiable"
end
- add_index "sections", ["phase_id"], name: "fk_rails_1853581585", using: :btree
-
create_table "settings", force: :cascade do |t|
- t.string "var", limit: 255, null: false
- t.text "value", limit: 65535
- t.integer "target_id", limit: 4, null: false
- t.string "target_type", limit: 255, null: false
- t.datetime "created_at"
- t.datetime "updated_at"
+ t.string "var", null: false
+ t.text "value"
+ t.integer "target_id", null: false
+ t.string "target_type", null: false
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
end
- add_index "settings", ["target_type", "target_id", "var"], name: "index_settings_on_target_type_and_target_id_and_var", unique: true, using: :btree
+ add_index "settings", ["target_type", "target_id", "var"], name: "index_settings_on_target_type_and_target_id_and_var", unique: true
create_table "splash_logs", force: :cascade do |t|
- t.string "destination", limit: 255
- t.datetime "created_at"
- t.datetime "updated_at"
+ t.string "destination"
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
end
create_table "suggested_answers", force: :cascade do |t|
- t.integer "question_id", limit: 4
- t.integer "org_id", limit: 4
- t.text "text", limit: 65535
+ t.integer "question_id"
+ t.integer "org_id"
+ t.text "text"
t.boolean "is_example"
t.datetime "created_at"
t.datetime "updated_at"
end
- add_index "suggested_answers", ["org_id"], name: "fk_rails_473de65779", using: :btree
- add_index "suggested_answers", ["question_id"], name: "fk_rails_daa60b5b70", using: :btree
-
create_table "templates", force: :cascade do |t|
- t.string "title", limit: 255
- t.text "description", limit: 65535
+ t.string "title"
+ t.text "description"
t.boolean "published"
- t.integer "org_id", limit: 4
- t.string "locale", limit: 255
+ t.integer "org_id"
+ t.string "locale"
t.boolean "is_default"
t.datetime "created_at"
t.datetime "updated_at"
- t.integer "version", limit: 4
- t.integer "visibility", limit: 4
- t.integer "customization_of", limit: 4
- t.integer "dmptemplate_id", limit: 4
+ t.integer "version"
+ t.integer "visibility"
+ t.integer "customization_of"
+ t.integer "dmptemplate_id"
end
- add_index "templates", ["org_id"], name: "fk_rails_481431e1bd", using: :btree
-
create_table "themes", force: :cascade do |t|
- t.string "title", limit: 255
- t.text "description", limit: 65535
- t.datetime "created_at"
- t.datetime "updated_at"
- t.string "locale", limit: 255
+ t.string "title"
+ t.text "description"
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
+ t.string "locale"
end
create_table "themes_in_guidance", id: false, force: :cascade do |t|
- t.integer "theme_id", limit: 4
- t.integer "guidance_id", limit: 4
+ t.integer "theme_id"
+ t.integer "guidance_id"
end
- add_index "themes_in_guidance", ["guidance_id"], name: "fk_rails_a5ab9402df", using: :btree
- add_index "themes_in_guidance", ["theme_id"], name: "fk_rails_7d708f6f1e", using: :btree
-
create_table "token_permission_types", force: :cascade do |t|
- t.string "token_type", limit: 255
- t.text "text_description", limit: 65535
+ t.string "token_type"
+ t.text "text_description"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "user_identifiers", force: :cascade do |t|
- t.string "identifier", limit: 255
+ t.string "identifier"
t.datetime "created_at"
t.datetime "updated_at"
- t.integer "user_id", limit: 4
- t.integer "identifier_scheme_id", limit: 4
+ t.integer "user_id"
+ t.integer "identifier_scheme_id"
end
- add_index "user_identifiers", ["identifier_scheme_id"], name: "fk_rails_fe95df7db0", using: :btree
- add_index "user_identifiers", ["user_id"], name: "fk_rails_65c9a98cdb", using: :btree
-
create_table "users", force: :cascade do |t|
- t.string "firstname", limit: 255
- t.string "surname", limit: 255
- t.string "email", limit: 255, default: "", null: false
- t.string "shibboleth_id", limit: 255
+ t.string "firstname"
+ t.string "surname"
+ t.string "email", default: "", null: false
+ t.string "shibboleth_id"
t.datetime "created_at"
t.datetime "updated_at"
- t.string "encrypted_password", limit: 255, default: ""
- t.string "reset_password_token", limit: 255
+ t.string "encrypted_password", default: ""
+ t.string "reset_password_token"
t.datetime "reset_password_sent_at"
t.datetime "remember_created_at"
- t.integer "sign_in_count", limit: 4, default: 0
+ t.integer "sign_in_count", default: 0
t.datetime "current_sign_in_at"
t.datetime "last_sign_in_at"
- t.string "current_sign_in_ip", limit: 255
- t.string "last_sign_in_ip", limit: 255
- t.string "confirmation_token", limit: 255
+ t.string "current_sign_in_ip"
+ t.string "last_sign_in_ip"
+ t.string "confirmation_token"
t.datetime "confirmed_at"
t.datetime "confirmation_sent_at"
- t.string "invitation_token", limit: 255
+ t.string "invitation_token"
t.datetime "invitation_created_at"
t.datetime "invitation_sent_at"
t.datetime "invitation_accepted_at"
- t.string "other_organisation", limit: 255
+ t.string "other_organisation"
t.boolean "dmponline3"
t.boolean "accept_terms"
- t.integer "org_id", limit: 4
- t.string "api_token", limit: 255
- t.integer "invited_by_id", limit: 4
- t.string "invited_by_type", limit: 255
- t.integer "language_id", limit: 4
+ t.integer "org_id"
+ t.string "api_token"
+ t.integer "invited_by_id"
+ t.string "invited_by_type"
+ t.integer "language_id"
end
add_index "users", ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true, using: :btree
add_index "users", ["email"], name: "index_users_on_email", unique: true, using: :btree
add_index "users", ["invitation_token"], name: "index_users_on_invitation_token", unique: true, using: :btree
- add_index "users", ["language_id"], name: "fk_rails_45f4f12508", using: :btree
- add_index "users", ["org_id"], name: "fk_rails_e73753bccb", using: :btree
add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true, using: :btree
create_table "users_perms", id: false, force: :cascade do |t|
- t.integer "user_id", limit: 4
- t.integer "perm_id", limit: 4
+ t.integer "user_id"
+ t.integer "perm_id"
end
- add_index "users_perms", ["perm_id"], name: "fk_rails_457217c31c", using: :btree
add_index "users_perms", ["user_id", "perm_id"], name: "index_users_perms_on_user_id_and_perm_id", using: :btree
add_foreign_key "answers", "plans"
@@ -414,6 +383,8 @@
add_foreign_key "orgs", "languages"
add_foreign_key "orgs", "regions"
add_foreign_key "phases", "templates"
+ add_foreign_key "plan_guidance_groups", "guidance_groups"
+ add_foreign_key "plan_guidance_groups", "plans"
add_foreign_key "plans", "templates"
add_foreign_key "question_options", "questions"
add_foreign_key "questions", "question_formats"
diff --git a/test/functional/answers_controller_test.rb b/test/functional/answers_controller_test.rb
new file mode 100644
index 0000000..a671b57
--- /dev/null
+++ b/test/functional/answers_controller_test.rb
@@ -0,0 +1,74 @@
+class AnswersControllerTest < ActionDispatch::IntegrationTest
+
+ include Devise::Test::IntegrationHelpers
+
+ setup do
+ @user = User.last
+
+ scaffold_plan
+ end
+
+ # PUT/PATCH /[:locale]/answer/[:id]
+ # ----------------------------------------------------------
+ test "should be able to update an answer" do
+ sign_in @user
+
+ # Test an answer for each Querstion Format
+ QuestionFormat.all.each do |format|
+ question = Question.find_by(question_format: format)
+ template = question.section.phase.template
+
+ plan = Plan.create(title: "Testing Answer For #{format.title}",
+ template: template)
+
+ referrer = "/#{I18n.locale}/plans/#{plan.id}/phases/#{question.section.phase.id}/edit"
+
+ answer = Answer.create(user: @user, plan: plan, question: question,
+ text: "#{format.title} Tester")
+
+ if format.option_based
+
+ else
+ # Try creating one first
+ form_attributes = {answer: {text: "#{format.title} Tester",
+ user_id: @user.id, plan_id: plan.id,
+ question_id: question.id}}
+
+ put_answer(answer, form_attributes, referrer)
+
+ answer = Answer.find_by(user: @user, plan: plan, question: question)
+ assert_not answer.id.nil?, "expected the answer to have been created and for an id to be present after creating a #{format.title} question!"
+
+ # Try editing it
+ form_attributes = {answer: {text: "Tested", user_id: answer.user.id,
+ plan_id: answer.plan.id,
+ question_id: answer.question.id}}
+
+ put_answer(answer, form_attributes, referrer)
+
+ answer.reload
+
+puts answer.inspect
+
+ assert_not answer.id.nil?, "expected the answer to have been updated and for an id to be present after creating a #{format.title} question!"
+ assert_equal "Tested", answer.text, "expected the text to have been updated for a #{format.title} question!"
+
+ end
+ end
+ end
+
+
+ private
+ def put_answer(answer, attributes, referrer)
+ put answer_path(I18n.locale, answer), attributes, {'HTTP_REFERER': referrer}
+
+ assert_equal I18n.t('helpers.project.answer_recorded'), flash[:notice]
+ assert_response :redirect
+
+ follow_redirects
+
+ assert_response :success
+ assert_select '.main_page_content h1', Plan.model_name.human.pluralize.titleize
+
+ end
+end
\ No newline at end of file
diff --git a/test/functional/application_controller_test.rb b/test/functional/application_controller_test.rb
index 705724f..90ba2aa 100644
--- a/test/functional/application_controller_test.rb
+++ b/test/functional/application_controller_test.rb
@@ -7,6 +7,8 @@
@user = User.first
stub_blog_calls
+
+ scaffold_plan
end
# In order to test methods on the application controller, we must call routes
@@ -15,7 +17,7 @@
# ----------------------------------------------------------------
test "make sure unauthorized users are redirected to the root path" do
plan = Plan.first
- get project_path(I18n.locale, plan)
+ get plan_path(I18n.locale, plan)
assert_redirected_to "#{root_path}?locale=#{I18n.locale}"
end
@@ -28,7 +30,7 @@
# Verify that passing a locale in the URL will set the locale
other = I18n.available_locales.last
- get project_path(other, plan)
+ get plan_path(other, plan)
assert_redirected_to "#{root_path}?locale=#{I18n.locale}", "Expected the changed locale to appear in the query string"
assert_equal other, I18n.locale, "Expected the locale to have been set when passing it in URL"
end
@@ -44,7 +46,7 @@
get root_path
assert_equal @user.language.abbreviation.to_s, I18n.locale.to_s, "Expected the locale to have been set to the user's chosen language"
- assert "#{projects_path}".starts_with?("/#{@user.language.abbreviation}/"), "Expected the system to use the user's language specification"
+ assert "#{plans_path}".starts_with?("/#{@user.language.abbreviation}/"), "Expected the system to use the user's language specification"
end
end
@@ -60,7 +62,7 @@
get root_path
org_lang = Language.find(@user.org[:language_id]).abbreviation
assert_equal org_lang.to_s, I18n.locale.to_s, "Expected the locale to have been set to the org's chosen language"
- assert "#{projects_path}".starts_with?("/#{org_lang}/"), "Expected the system to use the org's language specification"
+ assert "#{plans_path}".starts_with?("/#{org_lang}/"), "Expected the system to use the org's language specification"
end
end
@@ -70,8 +72,8 @@
assert_equal root_path, session[:previous_url]
sign_in @user
- get projects_path
- assert_equal projects_path, session[:previous_url]
+ get plans_path
+ assert_equal plans_path, session[:previous_url]
end
end
diff --git a/test/functional/static_pages_controller_test.rb b/test/functional/static_pages_controller_test.rb
index f2cd2ff..d31c76d 100644
--- a/test/functional/static_pages_controller_test.rb
+++ b/test/functional/static_pages_controller_test.rb
@@ -3,8 +3,9 @@
include Devise::Test::IntegrationHelpers
setup do
- @public_plan = Plan.create!({title: 'Public Test Project', template: Template.first,
- org: Org.first, visibility: :publicly_visible})
+ @public_plan = Plan.create!({title: 'Public Test Project',
+ template: Template.first,
+ visibility: :publicly_visible})
end
# ----------------------------------------------------------
diff --git a/test/routing_test.rb b/test/routing_test.rb
index eeb10a6..b23a0a5 100644
--- a/test/routing_test.rb
+++ b/test/routing_test.rb
@@ -1,6 +1,12 @@
require 'test_helper'
class RoutingTest < ActionDispatch::IntegrationTest
+
+ include Devise::Test::IntegrationHelpers
+
+ setup do
+ scaffold_plan
+ end
# Routing for the home page
# -------------------------------------------------------------------
@@ -34,24 +40,16 @@
assert_routing public_plans_path(locale: I18n.locale), target
end
test 'GET /public_export should resolve to StaticPagesController#public_export' do
- project = Project.includes(:plans).where.not(plans: {id: nil}).first
- target = {controller: "static_pages", action: "public_export", locale: "#{I18n.locale}", id: project.id.to_s}
+ plan = Plan.first
+ target = {controller: "static_pages", action: "public_export", locale: "#{I18n.locale}", id: plan.id.to_s}
- assert_routing public_export_path(locale: I18n.locale, id: project), target
+ assert_routing public_export_path(locale: I18n.locale, id: plan), target
end
# OAuth - Based on providers identified in the en-UK locale file
# -------------------------------------------------------------------
- test "GET /users/auth/[:provider] should resolve to OmniauthCallbackController#passthru" do
- target = {controller: "users/omniauth_callbacks", action: "passthru"}
-
- IdentifierScheme.all.each do |scheme|
- assert_routing "/users/auth/#{scheme.name.downcase}", target
- end
- end
-
test "POST /auth/[:provider]/callback should resolve to OmniauthCallbackController#[:provider]" do
- IdentifierScheme.all.each do |scheme|
+ IdentifierScheme.where(active: true).all.each do |scheme|
target = {controller: "users/omniauth_callbacks", action: "#{scheme.name.downcase}"}
assert_routing "/users/auth/#{scheme.name.downcase}/callback", target
end
diff --git a/test/test_helper.rb b/test/test_helper.rb
index c5698d7..548aaf8 100644
--- a/test/test_helper.rb
+++ b/test/test_helper.rb
@@ -92,7 +92,8 @@
assert_response :redirect
assert_match "#{root_url}", @response.redirect_url
- follow_redirect!
+ follow_redirects
+
assert_response :success
assert_select '.welcome-message h2', I18n.t('welcome_title')
end
@@ -103,17 +104,36 @@
assert_match "#{root_url}", @response.redirect_url
# Sometimes Devise has an intermediary step prior to sending the user to the final destination
+ follow_redirects
+
+ assert_response :success
+ assert_select '.main_page_content h1', Plan.model_name.human.pluralize.titleize
+ end
+
+ # ----------------------------------------------------------------------
+ def follow_redirects
while @response.status >= 300 && @response.status < 400
follow_redirect!
end
-
- assert_response :success
- assert_select '.main_page_content h1', I18n.t('helpers.project.projects_title')
end
-
# UNIT TEST HELPERS
# ----------------------------------------------------------------------
+ def verify_deep_copy(object, exclusions)
+ clazz = Object.const_get(object.class.name)
+ assert clazz.respond_to?(:deep_copy), "#{object.class.name} does not have a deep_copy method!"
+
+ copy = clazz.deep_copy(object)
+ object.attributes.each do |name, val|
+ if exclusions.include?(name)
+ assert_not_equal object.send(name), copy.send(name), "expected the deep_copy of #{object.class.name}.#{name} to be unique in the copy"
+ else
+ assert_equal object.send(name), copy.send(name), "expected the deep_copy of #{object.class.name}.#{name} to match"
+ end
+ end
+ end
+
+ # ----------------------------------------------------------------------
def verify_has_many_relationship(object, new_association, initial_expected_count)
# Assumes that the association name matches the pluralized name of the class
rel = "#{class_name_to_attribute_name(new_association.class.name).pluralize}"
diff --git a/test/unit/phase_test.rb b/test/unit/phase_test.rb
index 33f6e6d..5e8fdac 100644
--- a/test/unit/phase_test.rb
+++ b/test/unit/phase_test.rb
@@ -37,6 +37,11 @@
end
# ---------------------------------------------------
+ test "deep copy" do
+ verify_deep_copy(@phase, ['id', 'created_at', 'updated_at', 'slug'])
+ end
+
+ # ---------------------------------------------------
test "can CRUD Phase" do
obj = Phase.create(title: 'Testing CRUD', template: @template, number: 4)
assert_not obj.id.nil?, "was expecting to be able to create a new Phase! - #{obj.errors.map{|f, m| f.to_s + ' ' + m}.join(', ')}"
diff --git a/test/unit/question_test.rb b/test/unit/question_test.rb
index f5f3d4d..d335d7b 100644
--- a/test/unit/question_test.rb
+++ b/test/unit/question_test.rb
@@ -65,28 +65,9 @@
end
# ---------------------------------------------------
-# TODO: amoeba gem doesn't seem to be in play anymore
-=begin
- test "should be able to clone a Question (should include its question_options, themes suggested_answers)" do
- Question.all.each do |question|
-puts question.inspect
- q = question.amoeba_dup
-
- assert_equal question.text, q.text, "expected the 'text' field to match"
- assert_equal question.default_value, q.default_value, "expected the 'default_value' field to match"
- assert_equal question.guidance, q.guidance, "expected the 'guidance' field to match"
- assert_equal question.number, q.number, "expected the 'number' field to match"
- assert_equal question.section, q.section, "expected the 'section' field to match"
- assert_equal question.question_format, q.question_format, "expected the 'question_format' field to match"
- assert_equal question.option_comment_display, q.option_comment_display, "expected the 'option_comment_display' field to match"
- assert_equal question.modifiable, q.modifiable, "expected the 'modifiable' field to match"
-
- assert q.question_options.eql?(question.question_options), "expected the clone to carry over all of the question_options instead got: original - #{question.question_options.count}, clone - #{q.question_options.count}"
- assert q.suggested_answers.eql?(question.suggested_answers), "expected the clone to carry over all of the suggested_answers instead got: original - #{question.suggested_answers.count}, clone - #{q.suggested_answers.count}"
- assert q.themes.eql?(question.themes), "expected the clone to carry over all of the suggested_answers instead got: original - #{question.themes.count}, clone - #{q.themes.count}"
- end
+ test "deep copy" do
+ verify_deep_copy(@question, ['id', 'created_at', 'updated_at'])
end
-=end
# ---------------------------------------------------
test "can CRUD Question" do
diff --git a/test/unit/section_test.rb b/test/unit/section_test.rb
index f827044..5a22b5f 100644
--- a/test/unit/section_test.rb
+++ b/test/unit/section_test.rb
@@ -27,6 +27,11 @@
end
# ---------------------------------------------------
+ test "deep copy" do
+ verify_deep_copy(@section, ['id', 'created_at', 'updated_at'])
+ end
+
+ # ---------------------------------------------------
test "can CRUD Section" do
obj = Section.create(phase: @template.phases.last, title: 'Tester', number: 9)
assert_not obj.id.nil?, "was expecting to be able to create a new Section: #{obj.errors.map{|f, m| f.to_s + ' ' + m}.join(', ')}"
diff --git a/test/unit/template_test.rb b/test/unit/template_test.rb
index cb8f9b9..b8e1807 100644
--- a/test/unit/template_test.rb
+++ b/test/unit/template_test.rb
@@ -31,6 +31,49 @@
assert a.valid?, "expected the 'org', 'version' and 'title' fields to be enough to create an Template! - #{a.errors.map{|f, m| f.to_s + ' ' + m}.join(', ')}"
end
+ # ---------------------------------------------------
+ test "deep copy" do
+ verify_deep_copy(@template, ['id', 'created_at', 'updated_at', 'slug'])
+ end
+
+ # ---------- has_customisations? ----------
+ test "has_customisations? correctly identifies if a given org has customised the template" do
+ # TODO: Not sure if this is still an applicable method
+
+ end
+
+
+ # ---------------------------------------------------
+ test "can CRUD Template" do
+ tmplt = Template.create(org: @org, version: 1, title: 'Tester')
+ assert_not tmplt.id.nil?, "was expecting to be able to create a new Template!"
+
+ tmplt.description = 'Testing an update'
+ tmplt.save!
+ tmplt.reload
+ assert_equal 'Testing an update', tmplt.description, "Was expecting to be able to update the description of the Template!"
+
+ assert tmplt.destroy!, "Was unable to delete the Template!"
+ end
+
+ # ---------------------------------------------------
+ test "can manage has_many relationship with Phase" do
+ phase = Phase.new(title: 'Test Phase', number: 2)
+ verify_has_many_relationship(@template, phase, @template.phases.count)
+ end
+
+ # ---------------------------------------------------
+ test "can manage has_many relationship with Plan" do
+ plan = Plan.new(title: 'Test Plan')
+ verify_has_many_relationship(@template, plan, @template.plans.count)
+ end
+
+ # ---------------------------------------------------
+ test "can manage belongs_to relationship with Org" do
+ tmplt = Template.new(title: 'My test', version: 1)
+ verify_belongs_to_relationship(tmplt, @org)
+ end
+
# ---------- settings ----------
# ---------------------------------------------------
test "settings should use defaults if none are defined" do
@@ -224,43 +267,5 @@
assert_equal(default_formatting, @template.settings(:export).formatting)
end
-
- # ---------- has_customisations? ----------
- test "has_customisations? correctly identifies if a given org has customised the template" do
- # TODO: Not sure if this is still an applicable method
-
- end
-
-
- # ---------------------------------------------------
- test "can CRUD Template" do
- tmplt = Template.create(org: @org, version: 1, title: 'Tester')
- assert_not tmplt.id.nil?, "was expecting to be able to create a new Template!"
-
- tmplt.description = 'Testing an update'
- tmplt.save!
- tmplt.reload
- assert_equal 'Testing an update', tmplt.description, "Was expecting to be able to update the description of the Template!"
-
- assert tmplt.destroy!, "Was unable to delete the Template!"
- end
-
- # ---------------------------------------------------
- test "can manage has_many relationship with Phase" do
- phase = Phase.new(title: 'Test Phase', number: 2)
- verify_has_many_relationship(@template, phase, @template.phases.count)
- end
-
- # ---------------------------------------------------
- test "can manage has_many relationship with Plan" do
- plan = Plan.new(title: 'Test Plan')
- verify_has_many_relationship(@template, plan, @template.plans.count)
- end
-
- # ---------------------------------------------------
- test "can manage belongs_to relationship with Org" do
- tmplt = Template.new(title: 'My test', version: 1)
- verify_belongs_to_relationship(tmplt, @org)
- end
end
diff --git a/test/unit/user_test.rb b/test/unit/user_test.rb
index 7198708..86dab2f 100644
--- a/test/unit/user_test.rb
+++ b/test/unit/user_test.rb
@@ -51,14 +51,17 @@
# ---------------------------------------------------
test "name returns the correct value" do
- # Name should return 'First Last'
- assert @user.name.include?(@user.firstname)
- assert @user.name.include?(@user.surname)
+ # 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
- assert_equal @user.email, @user.name
+ assert_equal @user.email, @user.name(false), "expected the email if there is no first and last name"
end
# ---------------------------------------------------