<%= _('Add a new section') %>
diff --git a/app/views/phases/_overview.html.erb b/app/views/phases/_overview.html.erb
index f216c85..c89d151 100644
--- a/app/views/phases/_overview.html.erb
+++ b/app/views/phases/_overview.html.erb
@@ -1,5 +1,5 @@
<%# locals: { phase } %>
-
+
<%= _('Instructions') %>
@@ -9,8 +9,7 @@
<%= raw(phase.description) %>
-
-
+
<% phase.sections.each do |s| %>
@@ -25,4 +24,4 @@
<% end %>
-
\ No newline at end of file
+
diff --git a/db/migrate/20180803105147_remove_published_from_sections.rb b/db/migrate/20180803105147_remove_published_from_sections.rb
new file mode 100644
index 0000000..03fa4b8
--- /dev/null
+++ b/db/migrate/20180803105147_remove_published_from_sections.rb
@@ -0,0 +1,8 @@
+class RemovePublishedFromSections < ActiveRecord::Migration
+ def up
+ remove_column :sections, :published, :boolean
+ end
+ def down
+ add_column :sections, :published, :boolean
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 2d5eebe..6bf71f9 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema.define(version: 20180713164120) do
+ActiveRecord::Schema.define(version: 20180803105147) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@@ -314,7 +314,6 @@
t.integer "number"
t.datetime "created_at"
t.datetime "updated_at"
- t.boolean "published"
t.integer "phase_id"
t.boolean "modifiable"
end
diff --git a/spec/factories/annotations.rb b/spec/factories/annotations.rb
index fc8562c..c698c89 100644
--- a/spec/factories/annotations.rb
+++ b/spec/factories/annotations.rb
@@ -3,12 +3,21 @@
# Table name: annotations
#
# id :integer not null, primary key
-# question_id :integer
-# org_id :integer
# text :text
# type :integer default(0), not null
# created_at :datetime
# updated_at :datetime
+# org_id :integer
+# question_id :integer
+#
+# Indexes
+#
+# index_annotations_on_question_id (question_id)
+#
+# Foreign Keys
+#
+# fk_rails_... (org_id => orgs.id)
+# fk_rails_... (question_id => questions.id)
#
FactoryBot.define do
diff --git a/spec/factories/answers.rb b/spec/factories/answers.rb
index d227aea..b6674f2 100644
--- a/spec/factories/answers.rb
+++ b/spec/factories/answers.rb
@@ -3,13 +3,24 @@
# Table name: answers
#
# id :integer not null, primary key
+# lock_version :integer default(0)
# text :text
-# plan_id :integer
-# user_id :integer
-# question_id :integer
# created_at :datetime
# updated_at :datetime
-# lock_version :integer default(0)
+# plan_id :integer
+# question_id :integer
+# user_id :integer
+#
+# Indexes
+#
+# index_answers_on_plan_id (plan_id)
+# index_answers_on_question_id (question_id)
+#
+# Foreign Keys
+#
+# fk_rails_... (plan_id => plans.id)
+# fk_rails_... (question_id => questions.id)
+# fk_rails_... (user_id => users.id)
#
FactoryBot.define do
diff --git a/spec/factories/guidance_groups.rb b/spec/factories/guidance_groups.rb
index f7e2b49..82c7b09 100644
--- a/spec/factories/guidance_groups.rb
+++ b/spec/factories/guidance_groups.rb
@@ -4,11 +4,19 @@
#
# id :integer not null, primary key
# name :string
-# org_id :integer
-# created_at :datetime not null
-# updated_at :datetime not null
# optional_subset :boolean
# published :boolean
+# created_at :datetime not null
+# updated_at :datetime not null
+# org_id :integer
+#
+# Indexes
+#
+# index_guidance_groups_on_org_id (org_id)
+#
+# Foreign Keys
+#
+# fk_rails_... (org_id => orgs.id)
#
FactoryBot.define do
diff --git a/spec/factories/guidances.rb b/spec/factories/guidances.rb
index 53e3d4b..d57c1a0 100644
--- a/spec/factories/guidances.rb
+++ b/spec/factories/guidances.rb
@@ -3,12 +3,20 @@
# Table name: guidances
#
# id :integer not null, primary key
+# published :boolean
# text :text
-# guidance_group_id :integer
# created_at :datetime not null
# updated_at :datetime not null
+# guidance_group_id :integer
# question_id :integer
-# published :boolean
+#
+# Indexes
+#
+# index_guidances_on_guidance_group_id (guidance_group_id)
+#
+# Foreign Keys
+#
+# fk_rails_... (guidance_group_id => guidance_groups.id)
#
FactoryBot.define do
diff --git a/spec/factories/notes.rb b/spec/factories/notes.rb
index d133a59..5aa5919 100644
--- a/spec/factories/notes.rb
+++ b/spec/factories/notes.rb
@@ -3,13 +3,22 @@
# Table name: notes
#
# id :integer not null, primary key
-# user_id :integer
-# text :text
# archived :boolean
-# answer_id :integer
# archived_by :integer
+# text :text
# created_at :datetime
# updated_at :datetime
+# answer_id :integer
+# user_id :integer
+#
+# Indexes
+#
+# index_notes_on_answer_id (answer_id)
+#
+# Foreign Keys
+#
+# fk_rails_... (answer_id => answers.id)
+# fk_rails_... (user_id => users.id)
#
FactoryBot.define do
diff --git a/spec/factories/org_identifiers.rb b/spec/factories/org_identifiers.rb
index 2663d43..dbfafef 100644
--- a/spec/factories/org_identifiers.rb
+++ b/spec/factories/org_identifiers.rb
@@ -3,12 +3,17 @@
# Table name: org_identifiers
#
# id :integer not null, primary key
-# identifier :string
# attrs :string
+# identifier :string
# created_at :datetime
# updated_at :datetime
-# org_id :integer
# identifier_scheme_id :integer
+# org_id :integer
+#
+# Foreign Keys
+#
+# fk_rails_... (identifier_scheme_id => identifier_schemes.id)
+# fk_rails_... (org_id => orgs.id)
#
FactoryBot.define do
diff --git a/spec/factories/orgs.rb b/spec/factories/orgs.rb
index aa76bf6..c4477f6 100644
--- a/spec/factories/orgs.rb
+++ b/spec/factories/orgs.rb
@@ -3,28 +3,33 @@
# Table name: orgs
#
# id :integer not null, primary key
-# name :string
# abbreviation :string
+# banner_text :text
+# contact_email :string
+# contact_name :string
+# feedback_email_msg :text
+# feedback_email_subject :string
+# feedback_enabled :boolean default(FALSE)
+# is_other :boolean
+# links :text
+# logo_file_name :string
+# logo_name :string
+# logo_uid :string
+# name :string
+# org_type :integer default(0), not null
+# sort_name :string
# target_url :string
# wayfless_entity :string
# created_at :datetime not null
# updated_at :datetime not null
-# parent_id :integer
-# is_other :boolean
-# sort_name :string
-# banner_text :text
-# logo_file_name :string
-# region_id :integer
# language_id :integer
-# logo_uid :string
-# logo_name :string
-# contact_email :string
-# org_type :integer default(0), not null
-# links :text default({"org"=>[]})
-# contact_name :string
-# feedback_enabled :boolean default(FALSE)
-# feedback_email_subject :string
-# feedback_email_msg :text
+# parent_id :integer
+# region_id :integer
+#
+# Foreign Keys
+#
+# fk_rails_... (language_id => languages.id)
+# fk_rails_... (region_id => regions.id)
#
FactoryBot.define do
diff --git a/spec/factories/perms.rb b/spec/factories/perms.rb
index a54255a..8138a87 100644
--- a/spec/factories/perms.rb
+++ b/spec/factories/perms.rb
@@ -11,5 +11,45 @@
FactoryBot.define do
factory :perm do
name { Faker::Company.catch_phrase }
+
+ trait :add_organisations do
+ name 'add_organisations'
+ initialize_with { Perm.find_or_create_by(name: name) }
+ end
+
+ trait :change_org_affiliation do
+ name 'change_org_affiliation'
+ initialize_with { Perm.find_or_create_by(name: name) }
+ end
+
+ trait :grant_permissions do
+ name 'grant_permissions'
+ initialize_with { Perm.find_or_create_by(name: name) }
+ end
+
+ trait :modify_templates do
+ name 'modify_templates'
+ initialize_with { Perm.find_or_create_by(name: name) }
+ end
+
+ trait :modify_guidance do
+ name 'modify_guidance'
+ initialize_with { Perm.find_or_create_by(name: name) }
+ end
+
+ trait :use_api do
+ name 'use_api'
+ initialize_with { Perm.find_or_create_by(name: name) }
+ end
+
+ trait :change_org_details do
+ name 'change_org_details'
+ initialize_with { Perm.find_or_create_by(name: name) }
+ end
+
+ trait :grant_api_to_orgs do
+ name 'grant_api_to_orgs'
+ initialize_with { Perm.find_or_create_by(name: name) }
+ end
end
end
diff --git a/spec/factories/phases.rb b/spec/factories/phases.rb
index 41b0f55..9cb7d85 100644
--- a/spec/factories/phases.rb
+++ b/spec/factories/phases.rb
@@ -3,14 +3,22 @@
# Table name: phases
#
# id :integer not null, primary key
-# title :string
# description :text
+# modifiable :boolean
# number :integer
-# template_id :integer
+# slug :string
+# title :string
# created_at :datetime
# updated_at :datetime
-# slug :string
-# modifiable :boolean
+# template_id :integer
+#
+# Indexes
+#
+# index_phases_on_template_id (template_id)
+#
+# Foreign Keys
+#
+# fk_rails_... (template_id => templates.id)
#
FactoryBot.define do
diff --git a/spec/factories/plans.rb b/spec/factories/plans.rb
index 5aaac06..bbb922b 100644
--- a/spec/factories/plans.rb
+++ b/spec/factories/plans.rb
@@ -3,25 +3,33 @@
# Table name: plans
#
# id :integer not null, primary key
-# title :string
-# template_id :integer
-# created_at :datetime
-# updated_at :datetime
-# slug :string
-# grant_number :string
-# identifier :string
-# description :text
-# principal_investigator :string
-# principal_investigator_identifier :string
+# complete :boolean default(FALSE)
# data_contact :string
-# funder_name :string
-# visibility :integer default(3), not null
# data_contact_email :string
# data_contact_phone :string
-# principal_investigator_email :string
-# principal_investigator_phone :string
+# description :text
# feedback_requested :boolean default(FALSE)
-# complete :boolean default(FALSE)
+# funder_name :string
+# grant_number :string
+# identifier :string
+# principal_investigator :string
+# principal_investigator_email :string
+# principal_investigator_identifier :string
+# principal_investigator_phone :string
+# slug :string
+# title :string
+# visibility :integer default(3), not null
+# created_at :datetime
+# updated_at :datetime
+# template_id :integer
+#
+# Indexes
+#
+# index_plans_on_template_id (template_id)
+#
+# Foreign Keys
+#
+# fk_rails_... (template_id => templates.id)
#
FactoryBot.define do
diff --git a/spec/factories/question_options.rb b/spec/factories/question_options.rb
index bbe919a..ed91536 100644
--- a/spec/factories/question_options.rb
+++ b/spec/factories/question_options.rb
@@ -3,12 +3,20 @@
# Table name: question_options
#
# id :integer not null, primary key
-# question_id :integer
-# text :string
-# number :integer
# is_default :boolean
+# number :integer
+# text :string
# created_at :datetime
# updated_at :datetime
+# question_id :integer
+#
+# Indexes
+#
+# index_question_options_on_question_id (question_id)
+#
+# Foreign Keys
+#
+# fk_rails_... (question_id => questions.id)
#
FactoryBot.define do
diff --git a/spec/factories/questions.rb b/spec/factories/questions.rb
index ac05c80..6015297 100644
--- a/spec/factories/questions.rb
+++ b/spec/factories/questions.rb
@@ -3,15 +3,24 @@
# Table name: questions
#
# id :integer not null, primary key
-# text :text
# default_value :text
+# modifiable :boolean
# number :integer
-# section_id :integer
+# option_comment_display :boolean default(TRUE)
+# text :text
# created_at :datetime
# updated_at :datetime
# question_format_id :integer
-# option_comment_display :boolean default(TRUE)
-# modifiable :boolean
+# section_id :integer
+#
+# Indexes
+#
+# index_questions_on_section_id (section_id)
+#
+# Foreign Keys
+#
+# fk_rails_... (question_format_id => question_formats.id)
+# fk_rails_... (section_id => sections.id)
#
FactoryBot.define do
diff --git a/spec/factories/roles.rb b/spec/factories/roles.rb
index 30eb3b6..f4422af 100644
--- a/spec/factories/roles.rb
+++ b/spec/factories/roles.rb
@@ -3,12 +3,22 @@
# Table name: roles
#
# id :integer not null, primary key
-# user_id :integer
-# plan_id :integer
-# created_at :datetime
-# updated_at :datetime
# access :integer default(0), not null
# active :boolean default(TRUE)
+# created_at :datetime
+# updated_at :datetime
+# plan_id :integer
+# user_id :integer
+#
+# Indexes
+#
+# index_roles_on_plan_id (plan_id)
+# index_roles_on_user_id (user_id)
+#
+# Foreign Keys
+#
+# fk_rails_... (plan_id => plans.id)
+# fk_rails_... (user_id => users.id)
#
FactoryBot.define do
diff --git a/spec/factories/sections.rb b/spec/factories/sections.rb
index 85de359..b7272ae 100644
--- a/spec/factories/sections.rb
+++ b/spec/factories/sections.rb
@@ -3,14 +3,21 @@
# Table name: sections
#
# id :integer not null, primary key
-# title :string
# description :text
+# modifiable :boolean
# number :integer
+# title :string
# created_at :datetime
# updated_at :datetime
-# published :boolean
# phase_id :integer
-# modifiable :boolean
+#
+# Indexes
+#
+# index_sections_on_phase_id (phase_id)
+#
+# Foreign Keys
+#
+# fk_rails_... (phase_id => phases.id)
#
FactoryBot.define do
@@ -18,7 +25,6 @@
title { Faker::Lorem.sentence }
description { Faker::Lorem.paragraph }
sequence(:number)
- published false
phase
modifiable false
end
diff --git a/spec/factories/templates.rb b/spec/factories/templates.rb
index f60a507..bcd4113 100644
--- a/spec/factories/templates.rb
+++ b/spec/factories/templates.rb
@@ -3,20 +3,32 @@
# Table name: templates
#
# id :integer not null, primary key
-# title :string
+# archived :boolean
+# customization_of :integer
# description :text
-# published :boolean
-# org_id :integer
-# locale :string
# is_default :boolean
-# created_at :datetime
-# updated_at :datetime
+# links :text
+# locale :string
+# published :boolean
+# title :string
# version :integer
# visibility :integer
-# customization_of :integer
+# created_at :datetime
+# updated_at :datetime
# family_id :integer
-# archived :boolean
-# links :text default({"funder"=>[], "sample_plan"=>[]})
+# org_id :integer
+#
+# Indexes
+#
+# index_templates_on_customization_of_and_version_and_org_id (customization_of,version,org_id) UNIQUE
+# index_templates_on_family_id (family_id)
+# index_templates_on_family_id_and_version (family_id,version) UNIQUE
+# index_templates_on_org_id (org_id)
+# template_organisation_dmptemplate_index (org_id,family_id)
+#
+# Foreign Keys
+#
+# fk_rails_... (org_id => orgs.id)
#
FactoryBot.define do
diff --git a/spec/factories/user_identifiers.rb b/spec/factories/user_identifiers.rb
index d838dd5..d338189 100644
--- a/spec/factories/user_identifiers.rb
+++ b/spec/factories/user_identifiers.rb
@@ -6,8 +6,17 @@
# identifier :string
# created_at :datetime
# updated_at :datetime
-# user_id :integer
# identifier_scheme_id :integer
+# user_id :integer
+#
+# Indexes
+#
+# index_user_identifiers_on_user_id (user_id)
+#
+# Foreign Keys
+#
+# fk_rails_... (identifier_scheme_id => identifier_schemes.id)
+# fk_rails_... (user_id => users.id)
#
FactoryBot.define do
diff --git a/spec/factories/users.rb b/spec/factories/users.rb
index 057937e..0f32562 100644
--- a/spec/factories/users.rb
+++ b/spec/factories/users.rb
@@ -3,38 +3,48 @@
# Table name: users
#
# id :integer not null, primary key
-# firstname :string
-# surname :string
-# email :string default(""), not null
-# orcid_id :string
-# shibboleth_id :string
-# created_at :datetime not null
-# updated_at :datetime not null
-# encrypted_password :string default("")
-# reset_password_token :string
-# reset_password_sent_at :datetime
-# remember_created_at :datetime
-# sign_in_count :integer default(0)
-# current_sign_in_at :datetime
-# last_sign_in_at :datetime
-# current_sign_in_ip :string
-# last_sign_in_ip :string
+# accept_terms :boolean
+# active :boolean default(TRUE)
+# api_token :string
+# confirmation_sent_at :datetime
# confirmation_token :string
# confirmed_at :datetime
-# confirmation_sent_at :datetime
-# invitation_token :string
+# current_sign_in_at :datetime
+# current_sign_in_ip :string
+# email :string(80) default(""), not null
+# encrypted_password :string default("")
+# firstname :string
+# invitation_accepted_at :datetime
# invitation_created_at :datetime
# invitation_sent_at :datetime
-# invitation_accepted_at :datetime
-# other_organisation :string
-# accept_terms :boolean
-# org_id :integer
-# api_token :string
-# invited_by_id :integer
+# invitation_token :string
# invited_by_type :string
-# language_id :integer
+# last_sign_in_at :datetime
+# last_sign_in_ip :string
+# other_organisation :string
# recovery_email :string
-# active :boolean default(TRUE)
+# remember_created_at :datetime
+# reset_password_sent_at :datetime
+# reset_password_token :string
+# sign_in_count :integer default(0)
+# surname :string
+# created_at :datetime not null
+# updated_at :datetime not null
+# invited_by_id :integer
+# language_id :integer
+# orcid_id :string
+# org_id :integer
+# shibboleth_id :string
+#
+# Indexes
+#
+# index_users_on_email (email) UNIQUE
+# index_users_on_org_id (org_id)
+#
+# Foreign Keys
+#
+# fk_rails_... (language_id => languages.id)
+# fk_rails_... (org_id => orgs.id)
#
FactoryBot.define do
diff --git a/spec/features/templates_spec.rb b/spec/features/templates_spec.rb
new file mode 100644
index 0000000..baa081b
--- /dev/null
+++ b/spec/features/templates_spec.rb
@@ -0,0 +1,57 @@
+require "rails_helper"
+
+RSpec.describe "Templates", type: :feature do
+
+ before do
+ @org = create(:org)
+ @template = create(:template, org: @org, phases: 2)
+ @template.phases.each { |phase| create_list(:section, 2, phase: phase) }
+ @user = create(:user, org: @org)
+ @user.perms << create(:perm, :modify_templates)
+ sign_in(@user)
+ end
+
+ scenario "Org admin edits a template", :js do
+ # Action
+ click_link "Admin"
+ click_link "Templates"
+
+ # Expectations
+ expect(current_path).to eql(organisational_org_admin_templates_path)
+
+ # Action
+ click_button "Actions"
+ click_link "Edit"
+
+ # Expectations
+ expect(current_path).to eql(edit_org_admin_template_path(@template))
+
+ # Action
+ within '#phase_1' do
+ click_link "Edit phase"
+ end
+
+ # Expectations
+ path = edit_org_admin_template_phase_path(@template, @template.phases.first)
+ expect(current_path).to eql(path)
+
+ # Action
+ # Open the panel for a new Section
+ find("a[href='#new_section']").click
+
+ within "#collapseSectionNew" do
+ fill_in :new_section_section_title, with: "My new section"
+ tinymce_fill_in :new_section_section_description,
+ "This is the description of my new section"
+ click_button "Save"
+ end
+
+ # Expectations
+ last_section = Section.last
+ expect(@template.sections.count).to eql(5)
+ expect(last_section.title).to eql("My new section")
+ expect(last_section.description).to match("This is the description of my new section")
+ expect(last_section.description).to match("
")
+ end
+
+end