diff --git a/Gemfile b/Gemfile index ae7d281..ebb1231 100644 --- a/Gemfile +++ b/Gemfile @@ -36,6 +36,10 @@ gem 'friendly_id' # ------------------------------------------------ +# BIT FIELDS +gem 'flag_shih_tzu' + +# ------------------------------------------------ # SUPER ADMIN SECTION gem 'activeadmin', github: 'activeadmin' @@ -64,9 +68,11 @@ gem 'jquery-rails' gem 'twitter-bootstrap-rails', '2.2.8' gem 'tinymce-rails' # WYSIWYG EDITOR +gem 'substance-rails', path: '../substance-rails' # SUBSTANCE EDITOR - WYSIWYG HTML EDITOR gem 'contact_us', '>= 1.2.0' # COULD BE EASILY REPLACED WITH OUR OWN CODE gem 'recaptcha' gem 'dragonfly' # LOGO UPLOAD +gem "substance-rails", path: "../substance-rails" # SUBSTANCE EDITOR # ------------------------------------------------ # EXPORTING diff --git a/Gemfile.lock b/Gemfile.lock index 855f159..1876112 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -25,6 +25,13 @@ rails (>= 3.0, < 5.1) rake (>= 0.8.7) +PATH + remote: ../substance-rails + specs: + substance-rails (0.0.2) + actionpack (>= 4.0) + railties (>= 4.0) + GEM remote: https://rubygems.org/ specs: @@ -138,6 +145,7 @@ faraday_middleware (~> 0.9) loofah (~> 2.0) sax-machine (~> 1.0) + flag_shih_tzu (0.3.15) formtastic (3.1.4) actionpack (>= 3.2.13) formtastic_i18n (0.6.0) @@ -368,6 +376,7 @@ devise_invitable dragonfly feedjira + flag_shih_tzu friendly_id htmltoword i18n-js (>= 3.0.0.rc11) @@ -395,6 +404,7 @@ sass-rails simplecov sqlite3 + substance-rails! swagger-docs therubyracer (>= 0.11.4) thin diff --git a/app/controllers/answers_controller.rb b/app/controllers/answers_controller.rb index e157e76..bd03be7 100644 --- a/app/controllers/answers_controller.rb +++ b/app/controllers/answers_controller.rb @@ -7,7 +7,12 @@ authorize @answer old_answer = @answer.plan.answer(@answer.question_id, false) proceed = false - @answer.text = params["answer-text-#{@answer.question_id}".to_sym] + +puts "NEW ANSWER" +puts @answer.inspect +puts "OLD ANSWER" +puts old_answer.inspect + if (old_answer.nil? && @answer.text != "") || ((!old_answer.nil?) && (old_answer.text != @answer.text)) then proceed = true end diff --git a/app/controllers/dmptemplates_controller.rb b/app/controllers/dmptemplates_controller.rb index 9c7f757..e4b8785 100644 --- a/app/controllers/dmptemplates_controller.rb +++ b/app/controllers/dmptemplates_controller.rb @@ -8,10 +8,17 @@ # GET /dmptemplates def admin_index authorize Dmptemplate - #institutional templates + +# TODO: Wouldn't make more sense here to just do the following (using new model names here)?: +# @dmptemplates_own = current_user.org.templates + @dmptemplates_own = Dmptemplate.own_institutional_templates(current_user.organisation_id) - #funders templates + +# TODO: Wouldn't make more sense here to just do the following?: +# @@dmptemplates_funders = Org.where(org_type: :funder).templates + @dmptemplates_funders = Dmptemplate.funders_templates + respond_to do |format| format.html # index.html.erb end diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index a653686..0d54c3e 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -39,9 +39,6 @@ @show_form = true end - @visibilities = Visibility.all - @default_visibility = @visibilities.select{ |v| v.default }.first - if user_signed_in? && @project.readable_by(current_user.id) then respond_to do |format| format.html # show.html.erb @@ -71,6 +68,10 @@ @always_guidance = get_always_available_guidance @institutions = orgs_of_type(constant("organisation_types.institution")) +# TODO: Would be better to determine if the user's org has templates here than in the view. +# Replace the if Dmptemplate.own_institutional_templates check in views/projects/new with: +# @own_org_has_templates = current_user.organisation.templates.empty? + respond_to do |format| format.html # new.html.erb end @@ -139,7 +140,7 @@ if user_signed_in? then attrs = project_params - + @project = Project.new(attrs) authorize @project @@ -183,8 +184,6 @@ if user_signed_in? && @project.editable_by(current_user.id) then attrs = project_params - attrs[:visibility] = Visibility.find(attrs[:visibility]) unless attrs[:visibility].nil? - if @project.update_attributes(attrs) respond_to do |format| format.html { redirect_to({:action => "show", :id => @project.slug, notice: I18n.t('helpers.project.success_update') }) } diff --git a/app/controllers/static_pages_controller.rb b/app/controllers/static_pages_controller.rb index c55f473..e9d109a 100644 --- a/app/controllers/static_pages_controller.rb +++ b/app/controllers/static_pages_controller.rb @@ -18,8 +18,7 @@ # GET /projects/publicly_available # ----------------------------------------------------------- def public_plans - public_visibility = Visibility.find_by(name: 'public') - @projects = Project.where(visibility: public_visibility).order(title: :asc) + @projects = Project.publicly_visible.order(title: :asc) end # GET /projects/[:project_slug]/public_export @@ -31,7 +30,7 @@ request.format = :pdf # if the project is designated as public - if @project.visibility == Visibility.find_by(name: 'public') + if @project.visibility == :publicly_visible @plan = @project.plans.first if !@plan.nil? diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb index 88848b8..84c458d 100644 --- a/app/helpers/projects_helper.rb +++ b/app/helpers/projects_helper.rb @@ -45,7 +45,7 @@ text = shared_num > 0 ? (t("helpers.yes_label") + " (with #{shared_num} people) ") : t("helpers.no_label") [ "dmp_td_small", text ] when 'visibility' - ["dmp_td_small", (project.is_public? ? t("helpers.project.public_visibility") : (project.is_test? ? t("helpers.project.test_visibility") : t("helpers.project.default_visibility")))] + ["dmp_td_small", (project.visibility.nil? ? I18n.t("helpers.project.visibilities.labels.organisationally_visible") : I18n.t("helpers.project.visibilities.labels.#{project.visibility}"))] when 'last_edited' [ "dmp_td_small", l(project.latest_update.to_date, formats: :short) ] when 'description' diff --git a/app/models/answer.rb b/app/models/answer.rb index a989c8f..9d2c914 100644 --- a/app/models/answer.rb +++ b/app/models/answer.rb @@ -6,6 +6,13 @@ belongs_to :plan has_and_belongs_to_many :options, join_table: "answers_options" - - attr_accessible :text, :plan_id, :question_id, :user_id, :option_ids , :as => [:default, :admin] + +# TODO: REMOVE AND HANDLE ATTRIBUTE SECURITY IN THE CONTROLLER! + attr_accessible :text, :plan_id, :question_id, :user_id, :option_ids, :plan, :user, :question, + :as => [:default, :admin] + + validates :user, :plan, :question, :text, presence: true + + # Make sure there is only one answer per question! +# validates :question, uniqueness: {scope: [:user, :plan], message: I18n.t('helpers.errors.answer.only_one_per_question')} end diff --git a/app/models/comment.rb b/app/models/comment.rb index b4af9f9..a2e2ea2 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -1,12 +1,15 @@ class Comment < ActiveRecord::Base #associations between tables + belongs_to :user + belongs_to :plan belongs_to :question - #fields - attr_accessible :question_id, :text, :user_id, :archived, :plan_id, :archived_by, :as => [:default, :admin] +# TODO: REMOVE AND HANDLE ATTRIBUTE SECURITY IN THE CONTROLLER! + attr_accessible :question_id, :text, :user_id, :archived, :plan_id, :archived_by, + :user, :plan, :question, :as => [:default, :admin] - + validates :user, :question, :plan, :text, presence: true def to_s "#{text}" diff --git a/app/models/dmptemplate.rb b/app/models/dmptemplate.rb index 1ef460c..2289167 100644 --- a/app/models/dmptemplate.rb +++ b/app/models/dmptemplate.rb @@ -1,33 +1,37 @@ class Dmptemplate < ActiveRecord::Base - include GlobalHelpers + include GlobalHelpers - attr_accessible :id, :organisation_id, :description, :published, :title, :user_id, :locale, - :phases, :projects, :organisation, - :is_default, :guidance_group_ids, :as => [:default, :admin] +# TODO: REMOVE AND HANDLE ATTRIBUTE SECURITY IN THE CONTROLLER! + attr_accessible :id, :organisation_id, :description, :published, :title, :user_id, :locale, + :phases, :projects, :organisation, + :is_default, :guidance_group_ids, :as => [:default, :admin] - #associations between tables - has_many :phases - has_many :versions, through: :phases - has_many :sections, through: :versions - has_many :questions, through: :sections - has_many :projects + #associations between tables + has_many :phases + has_many :versions, through: :phases + has_many :sections, through: :versions + has_many :questions, through: :sections + has_many :projects - #has_many :guidances needs to be removed and checked + #has_many :guidances needs to be removed and checked - belongs_to :organisation + belongs_to :organisation has_and_belongs_to_many :guidance_groups, join_table: "dmptemplates_guidance_groups" - accepts_nested_attributes_for :guidance_groups - accepts_nested_attributes_for :phases - accepts_nested_attributes_for :organisation - accepts_nested_attributes_for :projects +# TODO: REMOVE AND HANDLE ATTRIBUTE SECURITY IN THE CONTROLLER! + accepts_nested_attributes_for :guidance_groups + accepts_nested_attributes_for :phases + accepts_nested_attributes_for :organisation + accepts_nested_attributes_for :projects has_settings :export, class_name: 'Settings::Dmptemplate' do |s| s.key :export, defaults: Settings::Dmptemplate::DEFAULT_SETTINGS end + validates :organisation, :title, presence: true + ## # Converts a DMPtemplate object into a string containing it's title # @@ -36,6 +40,13 @@ "#{title}" end + +# TODO: Remove the following methods ... they are never called by anything and don't make sense here anyway: +# self.templates_org_type +# self.funders_templates +# self.own_institutional_templates +# self.funders_and_own_templates + ## # takes a type or organisation and returns all published templates from # organisations of that type @@ -116,6 +127,7 @@ return templates_list end +# TODO: Remove this! We should not be attempting to access an Org attribute through this class ## # Returns the string name of the organisation type of the organisation who # owns this dmptemplate diff --git a/app/models/exported_plan.rb b/app/models/exported_plan.rb index 3782b52..8cc149f 100644 --- a/app/models/exported_plan.rb +++ b/app/models/exported_plan.rb @@ -1,7 +1,8 @@ class ExportedPlan < ActiveRecord::Base include GlobalHelpers - attr_accessible :plan_id, :user_id, :format, :as => [:default, :admin] +# TODO: REMOVE AND HANDLE ATTRIBUTE SECURITY IN THE CONTROLLER! + attr_accessible :plan_id, :user_id, :format, :user, :plan, :as => [:default, :admin] #associations between tables belongs_to :plan @@ -10,6 +11,7 @@ VALID_FORMATS = ['csv', 'html', 'json', 'pdf', 'text', 'xml', 'docx'] validates :format, inclusion: { in: VALID_FORMATS, message: I18n.t('helpers.plan.export.not_valid_format') } + validates :plan, :format, presence: true # Store settings with the exported plan so it can be recreated later # if necessary (otherwise the settings associated with the plan at a @@ -18,6 +20,9 @@ s.key :export, defaults: Settings::Dmptemplate::DEFAULT_SETTINGS end +# TODO: Consider removing the accessor methods, they add no value. The view/controller could +# just access the value directly from the project/plan: exported_plan.plan.project.title + # Getters to match Settings::Dmptemplate::VALID_ADMIN_FIELDS def project_name name = self.plan.project.title diff --git a/app/models/plan.rb b/app/models/plan.rb index f25998c..96d3aea 100644 --- a/app/models/plan.rb +++ b/app/models/plan.rb @@ -1,6 +1,7 @@ class Plan < ActiveRecord::Base - attr_accessible :locked, :project_id, :version_id, :version, :plan_sections, :as => [:default, :admin] + attr_accessible :locked, :project_id, :version_id, :version, :plan_sections, + :Exported_plans, :as => [:default, :admin] A4_PAGE_HEIGHT = 297 #(in mm) A4_PAGE_WIDTH = 210 #(in mm) @@ -13,6 +14,7 @@ belongs_to :version has_many :answers has_many :plan_sections + has_many :exported_plans # accepts_nested_attributes_for :project accepts_nested_attributes_for :answers diff --git a/app/models/project.rb b/app/models/project.rb index 06e51ec..6af3276 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -1,13 +1,11 @@ class Project < ActiveRecord::Base include GlobalHelpers - + extend FriendlyId #associations between tables belongs_to :dmptemplate belongs_to :organisation - - belongs_to :visibility has_many :plans has_many :project_groups, :dependent => :destroy @@ -15,6 +13,9 @@ friendly_id :title, use: [:slugged, :history, :finders] + # public is a Ruby keyword so using publicly + enum visibility: [:organisationally_visible, :publicly_visible, :is_test, :privately_visible] + ## # returns the title of the project # diff --git a/app/models/user.rb b/app/models/user.rb index 398c264..bc8da32 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -15,7 +15,7 @@ has_many :user_org_roles has_many :project_groups, :dependent => :destroy has_many :user_role_types, through: :user_org_roles - + has_many :exported_plans has_many :user_identifiers has_many :identifier_schemes, through: :user_identifiers @@ -51,7 +51,7 @@ :firstname, :last_login,:login_count, :orcid_id, :password, :shibboleth_id, :user_status_id, :surname, :user_type_id, :organisation_id, :skip_invitation, :other_organisation, :accept_terms, :role_ids, :dmponline3, :api_token, - :organisation, :language, :language_id + :organisation, :language, :language_id, :exported_plans validates :email, email: true, allow_nil: true, uniqueness: true diff --git a/app/models/visibility.rb b/app/models/visibility.rb deleted file mode 100644 index 26f7270..0000000 --- a/app/models/visibility.rb +++ /dev/null @@ -1,5 +0,0 @@ -class Visibility < ActiveRecord::Base - has_many :projects - - validates :name, uniqueness: true, presence: true -end \ No newline at end of file diff --git a/app/views/dmptemplates/_show_question.html.erb b/app/views/dmptemplates/_show_question.html.erb index df79c2b..03ee743 100644 --- a/app/views/dmptemplates/_show_question.html.erb +++ b/app/views/dmptemplates/_show_question.html.erb @@ -19,7 +19,7 @@
<%= t("helpers.plan.export.#{field}") -%> <%= value -%>
- <% end %> - <% end %> - - <% @exported_plan.sections.each do |section| %> -<%= t('helpers.plan.export.pdf.question_not_answered') -%>
- <% else %> - <% q_format = question.question_format%> - - <% if q_format.title == t("helpers.checkbox") || q_format.title == t("helpers.multi_select_box") || - q_format.title == t("helpers.radio_buttons") || q_format.title == t("helpers.dropdown") then%> -<%= t("helpers.plan.export.#{field}") -%> <%= value -%>
+ <% end %> + <% end %> + + <% @exported_plan.sections.each do |section| %> +<%= t('helpers.plan.export.pdf.question_not_answered') -%>
+ <% else %> + <% q_format = question.question_format%> + + <% if q_format.title == t("helpers.checkbox") || q_format.title == t("helpers.multi_select_box") || + q_format.title == t("helpers.radio_buttons") || q_format.title == t("helpers.dropdown") then%> +Willkommen. Sie können nun ihren ersten DMP erstellen. Wählen Sie 'Plan erstellen' weiter unten aus, um zu beginnen.
" diff --git a/config/locales/en-UK.yml b/config/locales/en-UK.yml index 814afe1..fc6afca 100644 --- a/config/locales/en-UK.yml +++ b/config/locales/en-UK.yml @@ -338,7 +338,7 @@ about_us_label: "About" roadmap_label: "Future plans" help_label: "Help" - publicly_plans_label: "Public DMPs" + public_plans_label: "Public DMPs" contact_label: "Contact" jisc: "The %{organisation_abbreviation} is funded by" @@ -582,10 +582,17 @@ visibility: "Visibility" visibilities: - test: "Test or Practice Plan" - private: "Private (owners, co-owners, and admins only) See our Terms of Use." - organisational: "With others within your organization" - public: "Publicly on the web. Your DMP will appear on the Public DMPs page of this site." + labels: + privately_visible: "Private" + organisationally_visible: "Organisational" + publicly_visible: "Public" + is_test: "Test/Practice" + help_texts: + privately_visible: "Private (owners, co-owners, and administrators only) See our Terms of Use." + organisationally_visible: "Organisational (visibile to others within your organisation)" + publicly_visible: "Public (Your DMP will appear on the Public DMPs page of this site)" + is_test: "Test/Practice (your plan is not visible to other users) See our Terms of Use." + not_set: "Not specified (will be visible to others within your organisation by default)" project_settings_text: "The items you select here will be displayed in the table below. You can sort the data by each of these headings or filter by entering a text string in the search box." project_text_when_no_project: "Welcome. You are now ready to create your first DMP.Click the 'Create plan' button below to begin.
" diff --git a/config/locales/en-US.yml b/config/locales/en-US.yml index 5bc3a01..f3f02ba 100644 --- a/config/locales/en-US.yml +++ b/config/locales/en-US.yml @@ -567,10 +567,17 @@ visibility: "Visibility" visibilities: - test: "Test or Practice Plan" - private: "Private (owners, co-owners, and admins only) See our Terms of Use." - organisational: "With others within your organization" - public: "Publicly on the web. Your DMP will appear on the Public DMPs page of this site." + labels: + privately_visible: "Private" + organisationally_visible: "Organizational" + publicly_visible: "Public" + is_test: "Test/Practice" + help_texts: + privately_visible: "Private (owners, co-owners, and administrators only) See our Terms of Use." + organisationally_visible: "Organizational (visibile to others within your organization)" + publicly_visible: "Public (Your DMP will appear on the Public DMPs page of this site)" + is_test: "Test/Practice (your plan is not visible to other users) See our Terms of Use." + not_set: "Not specified (will be visible to others within your organization by default)" project_settings_text: "The items you select here will be displayed in the table below. You can sort the data by each of these headings or filter by entering a text string in the search box." project_text_when_no_project: "Welcome. You are now ready to create your first DMP.Click the 'Create plan' button below to begin.
" diff --git a/config/locales/es.yml b/config/locales/es.yml index 87d3142..fd9fa5b 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -455,12 +455,20 @@ project_static_info: "Este plan está basado en:" projects_title: "Mis planes" + test: "Plan de prueba o práctica" visibility: "Visibilidad" visibilities: - test: "Plan de prueba o práctica" - private: "Privado (propietarios, copropietarios y administradores solamente) Consulte nuestras Condiciones de uso." - organisational: "Con otros miembros de su organización" - public: "Publicamente en la web. Su DMP aparecerá en la página Public DMPs de este sitio." + labels: + privatelt_visible: "Privado" + organisationally_visible: "Organizativo" + publicly_visible: "Público" + is_test: "Prueba/Práctica" + help_texts: + privately_visible: "Privado (propietarios, copropietarios y administradores solamente) Consulte nuestras Condiciones de uso." + organisationally_visible: "Con otros miembros de su organización" + publicly_visible: "Publicamente en la web. Su DMP aparecerá en la página Public DMPs de este sitio." + is_test: "Prueba / Práctica (su plan no es visible para otros usuarios) Vea nuestras Condiciones de uso." + not_set: "No especificado (será visible para otros dentro de su organización de forma predeterminada)" project_settings_text: "Los items que seleccione se mostarán en la siguiente tabla. Puede ordenar los datos según sus encabezados o filtrar tecleando textos en la caja de búsqueda." project_text_when_no_project: "Bienvenido. Ya está listo para crear su primer PGD.Haga clic en el botón 'Crear un plan' para comenzar.
" diff --git a/config/locales/fr.yml b/config/locales/fr.yml index 84f60a2..eb50920 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -459,14 +459,21 @@ project_identifier_help_text: "Un identifiant approprié conforme aux prescriptions de l'organisme financeur ou de l'établissement." project_static_info: "Ce plan s'inspire de :" projects_title: "Mes plans" - + visibility: "Visibilité" visibilities: - test: "Test ou plan de pratique" - private: "Privé (propriétaires, copropriétaires et administrateurs uniquement) Consultez nos Conditions d'utilisation." - organisational: "Avec d'autres membres de votre organisation" - public: "Publiquement sur le web. Votre DMP apparaîtra sur la page Public DMPs de ce site." - + labels: + privately_visible: "Privé" + organisationally_visible: "Organisationnel" + publicly_visible: "Public" + is_test: "Test/Pratique" + help_texts: + privately_visible: "Privé (propriétaires, copropriétaires et administrateurs uniquement) Consultez nos Conditions d'utilisation." + organisationally_visible: "Avec d'autres membres de votre organisation" + publicly_visible: "Publiquement sur le web. Votre DMP apparaîtra sur la page Public DMPs de ce site." + is_test: "Test / Practice (votre plan n'est pas visible aux autres utilisateurs) Voir nos Conditions d'utilisation." + not_set: "Non spécifié (sera visible par d'autres personnes au sein de votre organisation par défaut)" + project_settings_text: "Les éléments que vous sélectionnez ici s'afficherontt dans le tableaiu ci-après. Vous pouvez trier les données à partir de chacune de ces en-tête ou les filtrer en tapant une chaîne de caractères dans la zone de recherche." project_text_when_no_project: "Bienvenue. Vous voilà prêt à créer votre premier DMP.Cliquez sur le bouton 'Créer un plan' ci-dessous pour commencer.
" project_text_when_project: "Dans le tableau ci-dessous figurent les plans que vous avez créés, ainsi que ceux que vous partagez avec d'autres.Vous pouvez à tout moment les modifier, les partager, les exporter, les effacer...
" diff --git a/config/locales/static_pages/de.static.yml.example b/config/locales/static_pages/de.static.yml.example index 3bf5260..bc6987b 100644 --- a/config/locales/static_pages/de.static.yml.example +++ b/config/locales/static_pages/de.static.yml.example @@ -188,4 +188,4 @@ public_plans_page: title: "Öffentliche DMPs" no_plans_body_text_html: "Es wurden noch keine DMPs veröffentlicht." - body_text_html: "Öffentliche DMPs sind Pläne, die mit dem DMPTool erstellt und öffentlich von ihren Eigentümern veröffentlicht werden. Sie werden nicht auf Qualität, Vollständigkeit oder die Einhaltung der funder Richtlinien überprüft." + body_text_html: "Öffentliche DMPs sind Pläne, die mit dem DMPTool erstellt und öffentlich von ihren Eigentümern veröffentlicht werden. Sie werden nicht auf Qualität, Vollständigkeit oder die Einhaltung der funder Richtlinien überprüft." \ No newline at end of file diff --git a/config/locales/static_pages/en-UK.static.yml.example b/config/locales/static_pages/en-UK.static.yml.example index 54e5f2a..8a7d774 100644 --- a/config/locales/static_pages/en-UK.static.yml.example +++ b/config/locales/static_pages/en-UK.static.yml.example @@ -218,5 +218,5 @@ public_plans_page: title: "Public DMPs" - no_plans_body_text_html: "No DMPs have been made public yet." body_text_html: "Public DMPs are plans created using the DMPTool and shared publicly by their owners. They are not vetted for quality, completeness, or adherence to funder guidelines." + no_plans_body_text_html: "There are no public DMPs." \ No newline at end of file diff --git a/config/locales/static_pages/en-US.static.yml.example b/config/locales/static_pages/en-US.static.yml.example index fa41df8..3f9f003 100644 --- a/config/locales/static_pages/en-US.static.yml.example +++ b/config/locales/static_pages/en-US.static.yml.example @@ -218,4 +218,5 @@ public_plans_page: title: "Public DMPs" - body_text_html: "Public DMPs are plans created using the DMPTool and shared publicly by their owners. They are not vetted for quality, completeness, or adherence to funder guidelines." \ No newline at end of file + body_text_html: "Public DMPs are plans created using the DMPTool and shared publicly by their owners. They are not vetted for quality, completeness, or adherence to funder guidelines." + no_plans_body_text_html: "There are no public DMPs." \ No newline at end of file diff --git a/db/migrate/20170105165111_create_visibilities.rb b/db/migrate/20170105165111_create_visibilities.rb deleted file mode 100644 index 5e72ee1..0000000 --- a/db/migrate/20170105165111_create_visibilities.rb +++ /dev/null @@ -1,11 +0,0 @@ -class CreateVisibilities < ActiveRecord::Migration - def change - create_table :visibilities do |t| - t.string :name - t.boolean :default, default: false - t.timestamps - end - - add_reference :projects, :visibility, foreign_key: true - end -end diff --git a/db/migrate/20170110092511_add_is_test_and_visibility_to_projects.rb b/db/migrate/20170110092511_add_is_test_and_visibility_to_projects.rb new file mode 100644 index 0000000..b20e27a --- /dev/null +++ b/db/migrate/20170110092511_add_is_test_and_visibility_to_projects.rb @@ -0,0 +1,5 @@ +class AddIsTestAndVisibilityToProjects < ActiveRecord::Migration + def change + add_column :projects, :visibility, :integer, null: false, default: 0 + end +end diff --git a/db/schema.rb b/db/schema.rb index 218a45e..acc7809 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,95 +11,95 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20170105165111) do +ActiveRecord::Schema.define(version: 20170110092511) do create_table "answers", force: :cascade do |t| - t.text "text" - t.integer "plan_id" - t.integer "user_id" - t.integer "question_id" + t.text "text", limit: 65535 + t.integer "plan_id", limit: 4 + t.integer "user_id", limit: 4 + t.integer "question_id", limit: 4 t.datetime "created_at" t.datetime "updated_at" end create_table "answers_options", id: false, force: :cascade do |t| - t.integer "answer_id", null: false - t.integer "option_id", null: false + t.integer "answer_id", limit: 4, null: false + t.integer "option_id", limit: 4, null: false end - add_index "answers_options", ["answer_id", "option_id"], name: "index_answers_options_on_answer_id_and_option_id" + add_index "answers_options", ["answer_id", "option_id"], name: "index_answers_options_on_answer_id_and_option_id", using: :btree create_table "comments", force: :cascade do |t| - t.integer "user_id" - t.integer "question_id" - t.text "text" + t.integer "user_id", limit: 4 + t.integer "question_id", limit: 4 + t.text "text", limit: 65535 t.datetime "created_at" t.datetime "updated_at" t.boolean "archived" - t.integer "plan_id" - t.integer "archived_by" + t.integer "plan_id", limit: 4 + t.integer "archived_by", limit: 4 end create_table "dmptemplates", force: :cascade do |t| - t.string "title" - t.text "description" + t.string "title", limit: 255 + t.text "description", limit: 65535 t.boolean "published" - t.integer "user_id" - t.integer "organisation_id" + t.integer "user_id", limit: 4 + t.integer "organisation_id", limit: 4 t.datetime "created_at" t.datetime "updated_at" - t.string "locale" + t.string "locale", limit: 255 t.boolean "is_default" end create_table "dmptemplates_guidance_groups", id: false, force: :cascade do |t| - t.integer "dmptemplate_id" - t.integer "guidance_group_id" + t.integer "dmptemplate_id", limit: 4 + t.integer "guidance_group_id", limit: 4 end create_table "exported_plans", force: :cascade do |t| - t.integer "plan_id" - t.integer "user_id" - t.string "format" + 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" end create_table "file_types", force: :cascade do |t| - t.string "name" - t.string "icon_name" - t.integer "icon_size" - t.string "icon_location" + 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" end create_table "file_uploads", force: :cascade do |t| - t.string "name" - t.string "title" - t.text "description" - t.integer "size" + t.string "name", limit: 255 + t.string "title", limit: 255 + t.text "description", limit: 65535 + t.integer "size", limit: 4 t.boolean "published" - t.string "location" - t.integer "file_type_id" + t.string "location", limit: 255 + t.integer "file_type_id", limit: 4 t.datetime "created_at" t.datetime "updated_at" end create_table "friendly_id_slugs", force: :cascade do |t| - t.string "slug", null: false - t.integer "sluggable_id", null: false + t.string "slug", limit: 255, null: false + t.integer "sluggable_id", limit: 4, 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 - 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" + 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 create_table "guidance_groups", force: :cascade do |t| - t.string "name" - t.integer "organisation_id" + t.string "name", limit: 255 + t.integer "organisation_id", limit: 4 t.datetime "created_at" t.datetime "updated_at" t.boolean "optional_subset" @@ -107,106 +107,106 @@ end create_table "guidance_in_group", id: false, force: :cascade do |t| - t.integer "guidance_id", null: false - t.integer "guidance_group_id", null: false + t.integer "guidance_id", limit: 4, null: false + t.integer "guidance_group_id", limit: 4, null: false end - add_index "guidance_in_group", ["guidance_id", "guidance_group_id"], name: "index_guidance_in_group_on_guidance_id_and_guidance_group_id" + add_index "guidance_in_group", ["guidance_id", "guidance_group_id"], name: "index_guidance_in_group_on_guidance_id_and_guidance_group_id", using: :btree create_table "guidances", force: :cascade do |t| - t.text "text" - t.integer "guidance_group_id" + t.text "text", limit: 65535 + t.integer "guidance_group_id", limit: 4 t.datetime "created_at" t.datetime "updated_at" - t.integer "question_id" + t.integer "question_id", limit: 4 t.boolean "published" end create_table "identifier_schemes", force: :cascade do |t| - t.string "name" - t.string "description" + t.string "name", limit: 255 + t.string "description", limit: 255 t.boolean "active" t.datetime "created_at" t.datetime "updated_at" end create_table "languages", force: :cascade do |t| - t.string "abbreviation" - t.string "description" - t.string "name" + t.string "abbreviation", limit: 255 + t.string "description", limit: 255 + t.string "name", limit: 255 t.boolean "default_language" end create_table "option_warnings", force: :cascade do |t| - t.integer "organisation_id" - t.integer "option_id" - t.text "text" + t.integer "organisation_id", limit: 4 + t.integer "option_id", limit: 4 + t.text "text", limit: 65535 t.datetime "created_at" t.datetime "updated_at" end create_table "options", force: :cascade do |t| - t.integer "question_id" - t.string "text" - t.integer "number" + t.integer "question_id", limit: 4 + t.string "text", limit: 255 + t.integer "number", limit: 4 t.boolean "is_default" t.datetime "created_at" t.datetime "updated_at" end create_table "org_token_permissions", force: :cascade do |t| - t.integer "organisation_id" - t.integer "token_permission_type_id" + t.integer "organisation_id", limit: 4 + t.integer "token_permission_type_id", limit: 4 t.datetime "created_at" t.datetime "updated_at" end create_table "organisation_types", force: :cascade do |t| - t.string "name" - t.text "description" + t.string "name", limit: 255 + t.text "description", limit: 65535 t.datetime "created_at" t.datetime "updated_at" end create_table "organisations", force: :cascade do |t| - t.string "name" - t.string "abbreviation" - t.string "target_url" - t.integer "organisation_type_id" - t.string "domain" - t.string "wayfless_entity" - t.integer "stylesheet_file_id" + t.string "name", limit: 255 + t.string "abbreviation", limit: 255 + t.string "target_url", limit: 255 + t.integer "organisation_type_id", limit: 4 + t.string "domain", limit: 255 + t.string "wayfless_entity", limit: 255 + t.integer "stylesheet_file_id", limit: 4 t.datetime "created_at" t.datetime "updated_at" - t.integer "parent_id" + t.integer "parent_id", limit: 4 t.boolean "is_other" - 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.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 end create_table "phases", force: :cascade do |t| - t.string "title" - t.text "description" - t.integer "number" - t.integer "dmptemplate_id" + t.string "title", limit: 255 + t.text "description", limit: 65535 + t.integer "number", limit: 4 + t.integer "dmptemplate_id", limit: 4 t.datetime "created_at" t.datetime "updated_at" - t.string "slug" + t.string "slug", limit: 255 end - add_index "phases", ["dmptemplate_id"], name: "index_phases_on_dmptemplate_id" - add_index "phases", ["slug"], name: "index_phases_on_slug", unique: true + add_index "phases", ["dmptemplate_id"], name: "index_phases_on_dmptemplate_id", using: :btree + add_index "phases", ["slug"], name: "index_phases_on_slug", unique: true, using: :btree create_table "plan_sections", force: :cascade do |t| - t.integer "user_id" - t.integer "section_id" - t.integer "plan_id" + t.integer "user_id", limit: 4 + t.integer "section_id", limit: 4 + t.integer "plan_id", limit: 4 t.datetime "created_at" t.datetime "updated_at" t.datetime "release_time" @@ -214,8 +214,8 @@ create_table "plans", force: :cascade do |t| t.boolean "locked" - t.integer "project_id" - t.integer "version_id" + t.integer "project_id", limit: 4 + t.integer "version_id", limit: 4 t.datetime "created_at" t.datetime "updated_at" end @@ -223,242 +223,240 @@ create_table "project_groups", force: :cascade do |t| t.boolean "project_creator" t.boolean "project_editor" - t.integer "user_id" - t.integer "project_id" + t.integer "user_id", limit: 4 + t.integer "project_id", limit: 4 t.datetime "created_at" t.datetime "updated_at" t.boolean "project_administrator" end create_table "project_guidance", id: false, force: :cascade do |t| - t.integer "project_id", null: false - t.integer "guidance_group_id", null: false + t.integer "project_id", limit: 4, null: false + t.integer "guidance_group_id", limit: 4, null: false end - add_index "project_guidance", ["project_id", "guidance_group_id"], name: "index_project_guidance_on_project_id_and_guidance_group_id" + add_index "project_guidance", ["project_id", "guidance_group_id"], name: "index_project_guidance_on_project_id_and_guidance_group_id", using: :btree create_table "projects", force: :cascade do |t| - t.string "title" - t.integer "dmptemplate_id" + t.string "title", limit: 255 + t.integer "dmptemplate_id", limit: 4 t.datetime "created_at" t.datetime "updated_at" - t.string "slug" - t.integer "organisation_id" - 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_id" + t.string "slug", limit: 255 + t.integer "organisation_id", limit: 4 + 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 end - add_index "projects", ["slug"], name: "index_projects_on_slug", unique: true + add_index "projects", ["slug"], name: "index_projects_on_slug", unique: true, using: :btree create_table "question_formats", force: :cascade do |t| - t.string "title" - t.text "description" + t.string "title", limit: 255 + t.text "description", limit: 65535 t.datetime "created_at" t.datetime "updated_at" end create_table "questions", force: :cascade do |t| - t.text "text" - t.text "default_value" - t.text "guidance" - t.integer "number" - t.integer "parent_id" - t.integer "dependency_id" - t.text "dependency_text" - t.integer "section_id" + t.text "text", limit: 65535 + t.text "default_value", limit: 65535 + t.text "guidance", limit: 65535 + t.integer "number", limit: 4 + t.integer "parent_id", limit: 4 + t.integer "dependency_id", limit: 4 + t.text "dependency_text", limit: 65535 + t.integer "section_id", limit: 4 t.datetime "created_at" t.datetime "updated_at" - t.integer "question_format_id" - t.boolean "option_comment_display", default: true + t.integer "question_format_id", limit: 4 + t.boolean "option_comment_display", default: true end create_table "questions_themes", id: false, force: :cascade do |t| - t.integer "question_id", null: false - t.integer "theme_id", null: false + t.integer "question_id", limit: 4, null: false + t.integer "theme_id", limit: 4, null: false end - add_index "questions_themes", ["question_id", "theme_id"], name: "index_questions_themes_on_question_id_and_theme_id" + add_index "questions_themes", ["question_id", "theme_id"], name: "index_questions_themes_on_question_id_and_theme_id", using: :btree create_table "region_groups", force: :cascade do |t| - t.integer "super_region_id" - t.integer "region_id" + t.integer "super_region_id", limit: 4 + t.integer "region_id", limit: 4 end create_table "regions", force: :cascade do |t| - t.string "abbreviation" - t.string "description" - t.string "name" + t.string "abbreviation", limit: 255 + t.string "description", limit: 255 + t.string "name", limit: 255 end create_table "roles", force: :cascade do |t| - t.string "name" + t.string "name", limit: 255 t.datetime "created_at" t.datetime "updated_at" t.boolean "role_in_plans" - t.integer "resource_id" - t.string "resource_type" + t.integer "resource_id", limit: 4 + t.string "resource_type", limit: 255 end - add_index "roles", ["name"], name: "index_roles_on_name" - add_index "roles", ["name"], name: "index_roles_on_name_and_resource_type_and_resource_id" + add_index "roles", ["name"], name: "index_roles_on_name", using: :btree + add_index "roles", ["name"], name: "index_roles_on_name_and_resource_type_and_resource_id", using: :btree create_table "sections", force: :cascade do |t| - t.string "title" - t.text "description" - t.integer "number" - t.integer "version_id" - t.integer "organisation_id" + t.string "title", limit: 255 + t.text "description", limit: 65535 + t.integer "number", limit: 4 + t.integer "version_id", limit: 4 + t.integer "organisation_id", limit: 4 t.datetime "created_at" t.datetime "updated_at" t.boolean "published" end create_table "settings", force: :cascade do |t| - t.string "var", null: false - t.text "value" - t.integer "target_id", null: false - t.string "target_type", null: false + 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" end - add_index "settings", ["target_type", "target_id", "var"], name: "index_settings_on_target_type_and_target_id_and_var", unique: true + add_index "settings", ["target_type", "target_id", "var"], name: "index_settings_on_target_type_and_target_id_and_var", unique: true, using: :btree create_table "splash_logs", force: :cascade do |t| - t.string "destination" + t.string "destination", limit: 255 t.datetime "created_at" t.datetime "updated_at" end create_table "suggested_answers", force: :cascade do |t| - t.integer "question_id" - t.integer "organisation_id" - t.text "text" + t.integer "question_id", limit: 4 + t.integer "organisation_id", limit: 4 + t.text "text", limit: 65535 t.datetime "created_at" t.datetime "updated_at" t.boolean "is_example" end create_table "themes", force: :cascade do |t| - t.string "title" - t.text "description" + t.string "title", limit: 255 + t.text "description", limit: 65535 t.datetime "created_at" t.datetime "updated_at" - t.string "locale" + t.string "locale", limit: 255 end create_table "themes_in_guidance", id: false, force: :cascade do |t| - t.integer "theme_id" - t.integer "guidance_id" + t.integer "theme_id", limit: 4 + t.integer "guidance_id", limit: 4 end create_table "token_permission_types", force: :cascade do |t| - t.string "token_type" - t.text "text_description" + t.string "token_type", limit: 255 + t.text "text_description", limit: 65535 t.datetime "created_at" t.datetime "updated_at" end create_table "user_identifiers", force: :cascade do |t| - t.string "identifier" + t.string "identifier", limit: 255 t.datetime "created_at" t.datetime "updated_at" - t.integer "user_id" - t.integer "identifier_scheme_id" + t.integer "user_id", limit: 4 + t.integer "identifier_scheme_id", limit: 4 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 "user_role_types", force: :cascade do |t| - t.string "name" - t.text "description" + t.string "name", limit: 255 + t.text "description", limit: 65535 t.datetime "created_at" t.datetime "updated_at" end create_table "user_statuses", force: :cascade do |t| - t.string "name" - t.text "description" + t.string "name", limit: 255 + t.text "description", limit: 65535 t.datetime "created_at" t.datetime "updated_at" end create_table "user_types", force: :cascade do |t| - t.string "name" - t.text "description" + t.string "name", limit: 255 + t.text "description", limit: 65535 t.datetime "created_at" t.datetime "updated_at" end create_table "users", force: :cascade do |t| - t.string "firstname" - t.string "surname" - t.string "email", default: "", null: false - t.string "orcid_id" - t.string "shibboleth_id" - t.integer "user_type_id" - t.integer "user_status_id" + t.string "firstname", limit: 255 + t.string "surname", limit: 255 + t.string "email", limit: 255, default: "", null: false + t.string "orcid_id", limit: 255 + t.string "shibboleth_id", limit: 255 + t.integer "user_type_id", limit: 4 + t.integer "user_status_id", limit: 4 t.datetime "created_at" t.datetime "updated_at" - t.string "encrypted_password", default: "" - t.string "reset_password_token" + t.string "encrypted_password", limit: 255, default: "" + t.string "reset_password_token", limit: 255 t.datetime "reset_password_sent_at" t.datetime "remember_created_at" - t.integer "sign_in_count", default: 0 + t.integer "sign_in_count", limit: 4, default: 0 t.datetime "current_sign_in_at" t.datetime "last_sign_in_at" - t.string "current_sign_in_ip" - t.string "last_sign_in_ip" - t.string "confirmation_token" + t.string "current_sign_in_ip", limit: 255 + t.string "last_sign_in_ip", limit: 255 + t.string "confirmation_token", limit: 255 t.datetime "confirmed_at" t.datetime "confirmation_sent_at" - t.string "invitation_token" + t.string "invitation_token", limit: 255 t.datetime "invitation_created_at" t.datetime "invitation_sent_at" t.datetime "invitation_accepted_at" - t.string "other_organisation" + t.string "other_organisation", limit: 255 t.boolean "dmponline3" t.boolean "accept_terms" - t.integer "organisation_id" - t.string "api_token" - t.integer "invited_by_id" - t.string "invited_by_type" - t.integer "language_id" + t.integer "organisation_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 end - add_index "users", ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true - add_index "users", ["email"], name: "index_users_on_email", unique: true - add_index "users", ["invitation_token"], name: "index_users_on_invitation_token", unique: true - add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true + 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", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true, using: :btree create_table "users_roles", id: false, force: :cascade do |t| - t.integer "user_id" - t.integer "role_id" + t.integer "user_id", limit: 4 + t.integer "role_id", limit: 4 end - add_index "users_roles", ["user_id", "role_id"], name: "index_users_roles_on_user_id_and_role_id" + add_index "users_roles", ["user_id", "role_id"], name: "index_users_roles_on_user_id_and_role_id", using: :btree create_table "versions", force: :cascade do |t| - t.string "title" - t.text "description" - t.integer "number" - t.integer "phase_id" + t.string "title", limit: 255 + t.text "description", limit: 65535 + t.integer "number", limit: 4 + t.integer "phase_id", limit: 4 t.datetime "created_at" t.datetime "updated_at" t.boolean "published" end - add_index "versions", ["phase_id"], name: "index_versions_on_phase_id" + add_index "versions", ["phase_id"], name: "index_versions_on_phase_id", using: :btree - create_table "visibilities", force: :cascade do |t| - t.string "name" - t.boolean "default", default: false - t.datetime "created_at" - t.datetime "updated_at" - end - + add_foreign_key "user_identifiers", "identifier_schemes" + add_foreign_key "user_identifiers", "users" end diff --git a/db/seeds.rb b/db/seeds.rb index 79d47bf..fe47b1f 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -2,18 +2,6 @@ # This file should contain all the record creation needed to seed the database with its default values. # The data can then be loaded with the rake db:seed (or created alongside the db with db:setup). -# Plan Visibilities -# ------------------------------------------------------- -visibilities = { - test: {name: 'test', default: false}, - private: {name: 'private', default: false}, - organisational: {name: 'organisational', default: true}, - public: {name: 'public', default: false} -} -visibilities.map{ |v| Visibility.create!(v) } - -# Plan Visibilities -# ------------------------------------------------------- languages = { 'English(UK)' => { abbreviation: 'en-UK', @@ -112,8 +100,8 @@ if IdentifierScheme.where(name: details[:name]).empty? scheme = IdentifierScheme.new({ name: details[:name], - auth_uri: details[:auth_uri], - user_uri: details[:user_uri] + description: details[:description], + active: details[:active] }) scheme.save! end diff --git a/lib/assets/javascripts/application.js b/lib/assets/javascripts/application.js index eeea9a8..6dc6135 100644 --- a/lib/assets/javascripts/application.js +++ b/lib/assets/javascripts/application.js @@ -19,7 +19,8 @@ //= require tinymce-jquery //= require i18n //= require i18n/translations - +//= require substance/substance.js +//= require substance-forms.js $( document ).ready(function() { diff --git a/lib/assets/javascripts/plans.js b/lib/assets/javascripts/plans.js index 0cda411..cb23721 100644 --- a/lib/assets/javascripts/plans.js +++ b/lib/assets/javascripts/plans.js @@ -529,8 +529,3 @@ $("#"+editor.id).closest(".accordion-group").find(".section-status:first").toggle_dirty(editor.id.split('-')[2], editor.isDirty()); }; - - - - - diff --git a/lib/assets/javascripts/projects.js b/lib/assets/javascripts/projects.js index 1319733..0645304 100644 --- a/lib/assets/javascripts/projects.js +++ b/lib/assets/javascripts/projects.js @@ -205,14 +205,22 @@ // ---------------------------------------------------------- $("#project_is_test").click(function(e){ if(this.checked){ - $("#project_is_public").prop('checked', false); + $("input[name='project[visibility]']").prop('disabled', true); + $(".is-test-label").show(); + }else{ + $("input[name='project[visibility]']").prop('disabled', false); + $(".is-test-label").hide(); } }); + // Handle the 'test' flag on page load // ---------------------------------------------------------- - $("#project_is_public").click(function(e){ - if(this.checked){ - $("#project_is_test").prop('checked', false); - } - }); + if($("#project_is_test").checked){ + $("input[name='project[visibility]']").prop('disabled', true); + $(".is-test-label").show(); + }else{ + $("input[name='project[visibility]']").prop('disabled', false); + $(".is-test-label").hide(); + } + }); diff --git a/lib/assets/stylesheets/application.css b/lib/assets/stylesheets/application.css index f4a3bdf..4a460e7 100644 --- a/lib/assets/stylesheets/application.css +++ b/lib/assets/stylesheets/application.css @@ -10,8 +10,11 @@ * * require jquery.ui.all *= require_self + *= require substance-forms.css + *= require substance/substance-reset.css + *= require font-awesome.min.css *= require bootstrap_and_overrides *= require bootstrap.css - *= require bootstrap_and_overrides.css.less *= require select2.css - */ + *= require bootstrap_and_overrides.css.less + */ \ No newline at end of file diff --git a/lib/assets/stylesheets/bootstrap_and_overrides.css.less b/lib/assets/stylesheets/bootstrap_and_overrides.css.less index e71ec49..a1c25e4 100644 --- a/lib/assets/stylesheets/bootstrap_and_overrides.css.less +++ b/lib/assets/stylesheets/bootstrap_and_overrides.css.less @@ -499,6 +499,12 @@ } +/**** Substance Editor ***/ +.sc-rich-text-area { + border: 1px solid #ddd; + padding: 20px 10px; + padding-bottom: 0px; +} @@ -744,6 +750,10 @@ margin-top:4px; } +.radio-label { + margin-left: 10px; +} + .sign_up_org_label{ margin: 0 0 6px 0; float:left; diff --git a/test/fixtures/organisations.yml b/test/fixtures/organisations.yml index df643f5..d98f1e2 100644 --- a/test/fixtures/organisations.yml +++ b/test/fixtures/organisations.yml @@ -15,7 +15,7 @@ name: 'Curation Centre' abbreviation: 'cc' organisation_type: organisation - contact_email: 'admin@example-curation-centre.org' + contact_email: 'admin@example.org' funder: name: 'Grant Funder' @@ -33,7 +33,6 @@ name: <%= "#{obj['name']} #{n}" %> domain: <%= "www.#{lbl}-#{n + 1}.org" %> organisation_type: <%= "#{lbl}" %> - contact_email: "admin@example-#{lbl}-#{n + 1}.org" <% end %> <% end %> @@ -54,4 +53,4 @@ language_id: en-UK logo_uid: '2016/08/30/1234abcd-complete-org.gif' logo_name: 'complete-org.gif' - contact_email: 'admin@example-complete-org.org' \ No newline at end of file + contact_email: 'admin@example.org' \ No newline at end of file diff --git a/test/fixtures/projects.yml b/test/fixtures/projects.yml index 09b7f37..2f21031 100644 --- a/test/fixtures/projects.yml +++ b/test/fixtures/projects.yml @@ -5,4 +5,5 @@ title: <%= "#{lbl} Project" %> dmptemplate: <%= lbl %> organisation: complete + visibility: 1 <% end %> \ No newline at end of file diff --git a/test/fixtures/visibilities.yml b/test/fixtures/visibilities.yml deleted file mode 100644 index 55faa6e..0000000 --- a/test/fixtures/visibilities.yml +++ /dev/null @@ -1,15 +0,0 @@ -test: - name: 'test' - default: false - -private: - name: 'private' - default: false - -organisational: - name: 'organisational' - default: true - -public: - name: 'public' - default: false \ No newline at end of file diff --git a/test/functional/answers_controller_test.rb b/test/functional/answers_controller_test.rb deleted file mode 100644 index 9981abc..0000000 --- a/test/functional/answers_controller_test.rb +++ /dev/null @@ -1,51 +0,0 @@ -require 'test_helper' - -class AnswersControllerTest < ActionController::TestCase -=begin - setup do - @answer = answers(:one) - end - - test "should get index" do - get :index - assert_response :success - assert_not_nil assigns(:answers) - end - - test "should get new" do - get :new - assert_response :success - end - - test "should create answer" do - assert_difference('Answer.count') do - post :create, answer: { text: @answer.text, plan_id: @answer.plan_id, question_id: @answer.question_id, user_id: @answer.user_id } - end - - assert_redirected_to answer_path(assigns(:answer)) - end - - test "should show answer" do - get :show, id: @answer - assert_response :success - end - - test "should get edit" do - get :edit, id: @answer - assert_response :success - end - - test "should update answer" do - put :update, id: @answer, answer: { text: @answer.text, plan_id: @answer.plan_id, question_id: @answer.question_id, user_id: @answer.user_id } - assert_redirected_to answer_path(assigns(:answer)) - end - - test "should destroy answer" do - assert_difference('Answer.count', -1) do - delete :destroy, id: @answer - end - - assert_redirected_to answers_path - end -=end -end diff --git a/test/functional/dmptemplates_controller_test.rb b/test/functional/dmptemplates_controller_test.rb deleted file mode 100644 index a3a7521..0000000 --- a/test/functional/dmptemplates_controller_test.rb +++ /dev/null @@ -1,51 +0,0 @@ -require 'test_helper' - -class DmptemplatesControllerTest < ActionController::TestCase -=begin - setup do - @dmptemplate = dmptemplates(:one) - end - - test "should get index" do - get :index - assert_response :success - assert_not_nil assigns(:dmptemplates) - end - - test "should get new" do - get :new - assert_response :success - end - - test "should create dmptemplate" do - assert_difference('Dmptemplate.count') do - post :create, dmptemplate: { organisation_id: @dmptemplate.organisation_id, description: @dmptemplate.description, published: @dmptemplate.published, title: @dmptemplate.title, user_id: @dmptemplate.user_id } - end - - assert_redirected_to dmptemplate_path(assigns(:dmptemplate)) - end - - test "should show dmptemplate" do - get :show, id: @dmptemplate - assert_response :success - end - - test "should get edit" do - get :edit, id: @dmptemplate - assert_response :success - end - - test "should update dmptemplate" do - put :update, id: @dmptemplate, dmptemplate: { organisation_id: @dmptemplate.organisation_id, description: @dmptemplate.description, published: @dmptemplate.published, title: @dmptemplate.title, user_id: @dmptemplate.user_id } - assert_redirected_to dmptemplate_path(assigns(:dmptemplate)) - end - - test "should destroy dmptemplate" do - assert_difference('Dmptemplate.count', -1) do - delete :destroy, id: @dmptemplate - end - - assert_redirected_to dmptemplates_path - end -=end -end diff --git a/test/functional/file_types_controller_test.rb b/test/functional/file_types_controller_test.rb deleted file mode 100644 index 168c370..0000000 --- a/test/functional/file_types_controller_test.rb +++ /dev/null @@ -1,51 +0,0 @@ -require 'test_helper' - -class FileTypesControllerTest < ActionController::TestCase -=begin - setup do - @file_type = file_types(:one) - end - - test "should get index" do - get :index - assert_response :success - assert_not_nil assigns(:file_types) - end - - test "should get new" do - get :new - assert_response :success - end - - test "should create file_type" do - assert_difference('FileType.count') do - post :create, file_type: { name: @file_type.name, icon_location: @file_type.icon_location, icon_name: @file_type.icon_name, icon_size: @file_type.icon_size } - end - - assert_redirected_to file_type_path(assigns(:file_type)) - end - - test "should show file_type" do - get :show, id: @file_type - assert_response :success - end - - test "should get edit" do - get :edit, id: @file_type - assert_response :success - end - - test "should update file_type" do - put :update, id: @file_type, file_type: { name: @file_type.name, icon_location: @file_type.icon_location, icon_name: @file_type.icon_name, icon_size: @file_type.icon_size } - assert_redirected_to file_type_path(assigns(:file_type)) - end - - test "should destroy file_type" do - assert_difference('FileType.count', -1) do - delete :destroy, id: @file_type - end - - assert_redirected_to file_types_path - end -=end -end diff --git a/test/functional/file_uploads_controller_test.rb b/test/functional/file_uploads_controller_test.rb deleted file mode 100644 index 41a1a64..0000000 --- a/test/functional/file_uploads_controller_test.rb +++ /dev/null @@ -1,51 +0,0 @@ -require 'test_helper' - -class FileUploadsControllerTest < ActionController::TestCase -=begin - setup do - @file_upload = file_uploads(:one) - end - - test "should get index" do - get :index - assert_response :success - assert_not_nil assigns(:file_uploads) - end - - test "should get new" do - get :new - assert_response :success - end - - test "should create file_upload" do - assert_difference('FileUpload.count') do - post :create, file_upload: { file_type_id: @file_upload.file_type_id, description: @file_upload.description, location: @file_upload.location, name: @file_upload.name, published: @file_upload.published, size: @file_upload.size, title: @file_upload.title } - end - - assert_redirected_to file_upload_path(assigns(:file_upload)) - end - - test "should show file_upload" do - get :show, id: @file_upload - assert_response :success - end - - test "should get edit" do - get :edit, id: @file_upload - assert_response :success - end - - test "should update file_upload" do - put :update, id: @file_upload, file_upload: { file_type_id: @file_upload.file_type_id, description: @file_upload.description, location: @file_upload.location, name: @file_upload.name, published: @file_upload.published, size: @file_upload.size, title: @file_upload.title } - assert_redirected_to file_upload_path(assigns(:file_upload)) - end - - test "should destroy file_upload" do - assert_difference('FileUpload.count', -1) do - delete :destroy, id: @file_upload - end - - assert_redirected_to file_uploads_path - end -=end -end diff --git a/test/functional/guidances_controller_test.rb b/test/functional/guidances_controller_test.rb deleted file mode 100644 index 2dc60d1..0000000 --- a/test/functional/guidances_controller_test.rb +++ /dev/null @@ -1,51 +0,0 @@ -require 'test_helper' - -class GuidancesControllerTest < ActionController::TestCase -=begin - setup do - @guidance = guidances(:one) - end - - test "should get index" do - get :index - assert_response :success - assert_not_nil assigns(:guidances) - end - - test "should get new" do - get :new - assert_response :success - end - - test "should create guidance" do - assert_difference('Guidance.count') do - post :create, guidance: { file_id: @guidance.file_id, text: @guidance.text, organisation_id: @guidance.organisation_id, theme_id: @guidance.theme_id } - end - - assert_redirected_to guidance_path(assigns(:guidance)) - end - - test "should show guidance" do - get :show, id: @guidance - assert_response :success - end - - test "should get edit" do - get :edit, id: @guidance - assert_response :success - end - - test "should update guidance" do - put :update, id: @guidance, guidance: { file_id: @guidance.file_id, text: @guidance.text, organisation_id: @guidance.organisation_id, theme_id: @guidance.theme_id } - assert_redirected_to guidance_path(assigns(:guidance)) - end - - test "should destroy guidance" do - assert_difference('Guidance.count', -1) do - delete :destroy, id: @guidance - end - - assert_redirected_to guidances_path - end -=end -end diff --git a/test/functional/home_controller_test.rb b/test/functional/home_controller_test.rb deleted file mode 100644 index d088a29..0000000 --- a/test/functional/home_controller_test.rb +++ /dev/null @@ -1,10 +0,0 @@ -require 'test_helper' - -class HomeControllerTest < ActionController::TestCase -=begin - test "should get index" do - get :index - assert_response :success - end -=end -end diff --git a/test/functional/organisation_types_controller_test.rb b/test/functional/organisation_types_controller_test.rb deleted file mode 100644 index 380dd88..0000000 --- a/test/functional/organisation_types_controller_test.rb +++ /dev/null @@ -1,51 +0,0 @@ -require 'test_helper' - -class OrganisationTypesControllerTest < ActionController::TestCase -=begin - setup do - @organisation_type = organisation_types(:one) - end - - test "should get index" do - get :index - assert_response :success - assert_not_nil assigns(:organisation_types) - end - - test "should get new" do - get :new - assert_response :success - end - - test "should create organisation_type" do - assert_difference('OrganisationType.count') do - post :create, organisation_type: { description: @organisation_type.description, name: @organisation_type.name } - end - - assert_redirected_to organisation_type_path(assigns(:organisation_type)) - end - - test "should show organisation_type" do - get :show, id: @organisation_type - assert_response :success - end - - test "should get edit" do - get :edit, id: @organisation_type - assert_response :success - end - - test "should update organisation_type" do - put :update, id: @organisation_type, organisation_type: { description: @organisation_type.description, name: @organisation_type.name } - assert_redirected_to organisation_type_path(assigns(:organisation_type)) - end - - test "should destroy organisation_type" do - assert_difference('OrganisationType.count', -1) do - delete :destroy, id: @organisation_type - end - - assert_redirected_to organisation_types_path - end -=end -end diff --git a/test/functional/organisations_controller_test.rb b/test/functional/organisations_controller_test.rb deleted file mode 100644 index c43d4f4..0000000 --- a/test/functional/organisations_controller_test.rb +++ /dev/null @@ -1,51 +0,0 @@ -require 'test_helper' - -class OrganisationsControllerTest < ActionController::TestCase -=begin - setup do - @organisation = organisations(:one) - end - - test "should get index" do - get :index - assert_response :success - assert_not_nil assigns(:organisations) - end - - test "should get new" do - get :new - assert_response :success - end - - test "should create organisation" do - assert_difference('Organisation.count') do - post :create, organisation: { abbreviation: @organisation.abbreviation, banner_file_id: @organisation.banner_file_id, description: @organisation.description, domain: @organisation.domain, logo_file_id: @organisation.logo_file_id, name: @organisation.name, stylesheet_file_id: @organisation.stylesheet_file_id, target_url: @organisation.target_url, type_id: @organisation.type_id, wayfless_entite: @organisation.wayfless_entite } - end - - assert_redirected_to organisation_path(assigns(:organisation)) - end - - test "should show organisation" do - get :show, id: @organisation - assert_response :success - end - - test "should get edit" do - get :edit, id: @organisation - assert_response :success - end - - test "should update organisation" do - put :update, id: @organisation, organisation: { abbreviation: @organisation.abbreviation, banner_file_id: @organisation.banner_file_id, description: @organisation.description, domain: @organisation.domain, logo_file_id: @organisation.logo_file_id, name: @organisation.name, stylesheet_file_id: @organisation.stylesheet_file_id, target_url: @organisation.target_url, type_id: @organisation.type_id, wayfless_entite: @organisation.wayfless_entite } - assert_redirected_to organisation_path(assigns(:organisation)) - end - - test "should destroy organisation" do - assert_difference('Organisation.count', -1) do - delete :destroy, id: @organisation - end - - assert_redirected_to organisations_path - end -=end -end diff --git a/test/functional/pages_controller_test.rb b/test/functional/pages_controller_test.rb deleted file mode 100644 index b525098..0000000 --- a/test/functional/pages_controller_test.rb +++ /dev/null @@ -1,51 +0,0 @@ -require 'test_helper' - -class PagesControllerTest < ActionController::TestCase -=begin - setup do - @page = pages(:one) - end - - test "should get index" do - get :index - assert_response :success - assert_not_nil assigns(:pages) - end - - test "should get new" do - get :new - assert_response :success - end - - test "should create page" do - assert_difference('Page.count') do - post :create, page: { organisation_id: @page.organisation_id, body_text: @page.body_text, location: @page.location, menu: @page.menu, menu_position: @page.menu_position, public: @page.public, slug: @page.slug, target_url: @page.target_url, title: @page.title } - end - - assert_redirected_to page_path(assigns(:page)) - end - - test "should show page" do - get :show, id: @page - assert_response :success - end - - test "should get edit" do - get :edit, id: @page - assert_response :success - end - - test "should update page" do - put :update, id: @page, page: { organisation_id: @page.organisation_id, body_text: @page.body_text, location: @page.location, menu: @page.menu, menu_position: @page.menu_position, public: @page.public, slug: @page.slug, target_url: @page.target_url, title: @page.title } - assert_redirected_to page_path(assigns(:page)) - end - - test "should destroy page" do - assert_difference('Page.count', -1) do - delete :destroy, id: @page - end - - assert_redirected_to pages_path - end -=end -end diff --git a/test/functional/phases_controller_test.rb b/test/functional/phases_controller_test.rb deleted file mode 100644 index b392886..0000000 --- a/test/functional/phases_controller_test.rb +++ /dev/null @@ -1,51 +0,0 @@ -require 'test_helper' - -class PhasesControllerTest < ActionController::TestCase -=begin - setup do - @phase = phases(:one) - end - - test "should get index" do - get :index - assert_response :success - assert_not_nil assigns(:phases) - end - - test "should get new" do - get :new - assert_response :success - end - - test "should create phase" do - assert_difference('Phase.count') do - post :create, phase: { description: @phase.description, order: @phase.order, title: @phase.title } - end - - assert_redirected_to phase_path(assigns(:phase)) - end - - test "should show phase" do - get :show, id: @phase - assert_response :success - end - - test "should get edit" do - get :edit, id: @phase - assert_response :success - end - - test "should update phase" do - put :update, id: @phase, phase: { description: @phase.description, order: @phase.order, title: @phase.title } - assert_redirected_to phase_path(assigns(:phase)) - end - - test "should destroy phase" do - assert_difference('Phase.count', -1) do - delete :destroy, id: @phase - end - - assert_redirected_to phases_path - end -=end -end diff --git a/test/functional/plan_sections_controller_test.rb b/test/functional/plan_sections_controller_test.rb deleted file mode 100644 index 97bbe62..0000000 --- a/test/functional/plan_sections_controller_test.rb +++ /dev/null @@ -1,51 +0,0 @@ -require 'test_helper' - -class PlanSectionsControllerTest < ActionController::TestCase -=begin - setup do - @plan_section = plan_sections(:one) - end - - test "should get index" do - get :index - assert_response :success - assert_not_nil assigns(:plan_sections) - end - - test "should get new" do - get :new - assert_response :success - end - - test "should create plan_section" do - assert_difference('PlanSection.count') do - post :create, plan_section: { plan_id: @plan_section.plan_id, at: @plan_section.at, edit: @plan_section.edit, section_id: @plan_section.section_id, user_editing_id: @plan_section.user_editing_id } - end - - assert_redirected_to plan_section_path(assigns(:plan_section)) - end - - test "should show plan_section" do - get :show, id: @plan_section - assert_response :success - end - - test "should get edit" do - get :edit, id: @plan_section - assert_response :success - end - - test "should update plan_section" do - put :update, id: @plan_section, plan_section: { plan_id: @plan_section.plan_id, at: @plan_section.at, edit: @plan_section.edit, section_id: @plan_section.section_id, user_editing_id: @plan_section.user_editing_id } - assert_redirected_to plan_section_path(assigns(:plan_section)) - end - - test "should destroy plan_section" do - assert_difference('PlanSection.count', -1) do - delete :destroy, id: @plan_section - end - - assert_redirected_to plan_sections_path - end -=end -end diff --git a/test/functional/plans_controller_test.rb b/test/functional/plans_controller_test.rb deleted file mode 100644 index 58e763f..0000000 --- a/test/functional/plans_controller_test.rb +++ /dev/null @@ -1,47 +0,0 @@ -require 'test_helper' - -class PlansControllerTest < ActionController::TestCase -=begin - test "should get index" do - get :index - assert_response :success - assert_not_nil assigns(:plans) - end - - test "should get new" do - get :new - assert_response :success - end - - test "should create plan" do - assert_difference('Plan.count') do - post :create, plan: { locked: @plan.locked, project_id: @plan.project_id, version_id: @plan.version_id } - end - - assert_redirected_to plan_path(assigns(:plan)) - end - - test "should show plan" do - get :show, id: @plan - assert_response :success - end - - test "should get edit" do - get :edit, id: @plan - assert_response :success - end - - test "should update plan" do - put :update, id: @plan, plan: { locked: @plan.locked, project_id: @plan.project_id, version_id: @plan.version_id } - assert_redirected_to plan_path(assigns(:plan)) - end - - test "should destroy plan" do - assert_difference('Plan.count', -1) do - delete :destroy, id: @plan - end - - assert_redirected_to plans_path - end -=end -end diff --git a/test/functional/project_groups_controller_test.rb b/test/functional/project_groups_controller_test.rb deleted file mode 100644 index 0e129f1..0000000 --- a/test/functional/project_groups_controller_test.rb +++ /dev/null @@ -1,51 +0,0 @@ -require 'test_helper' - -class ProjectGroupsControllerTest < ActionController::TestCase -=begin - setup do - @project_group = project_groups(:one) - end - - test "should get index" do - get :index - assert_response :success - assert_not_nil assigns(:project_groups) - end - - test "should get new" do - get :new - assert_response :success - end - - test "should create project_group" do - assert_difference('ProjectGroup.count') do - post :create, project_group: { project_creator: @project_group.project_creator, project_editor: @project_group.project_editor, project_id: @project_group.project_id, user_id: @project_group.user_id } - end - - assert_redirected_to project_group_path(assigns(:project_group)) - end - - test "should show project_group" do - get :show, id: @project_group - assert_response :success - end - - test "should get edit" do - get :edit, id: @project_group - assert_response :success - end - - test "should update project_group" do - put :update, id: @project_group, project_group: { project_creator: @project_group.project_creator, project_editor: @project_group.project_editor, project_id: @project_group.project_id, user_id: @project_group.user_id } - assert_redirected_to project_group_path(assigns(:project_group)) - end - - test "should destroy project_group" do - assert_difference('ProjectGroup.count', -1) do - delete :destroy, id: @project_group - end - - assert_redirected_to project_groups_path - end -=end -end diff --git a/test/functional/project_partners_controller_test.rb b/test/functional/project_partners_controller_test.rb deleted file mode 100644 index c975fb2..0000000 --- a/test/functional/project_partners_controller_test.rb +++ /dev/null @@ -1,51 +0,0 @@ -require 'test_helper' - -class ProjectPartnersControllerTest < ActionController::TestCase -=begin - setup do - @project_partner = project_partners(:one) - end - - test "should get index" do - get :index - assert_response :success - assert_not_nil assigns(:project_partners) - end - - test "should get new" do - get :new - assert_response :success - end - - test "should create project_partner" do - assert_difference('ProjectPartner.count') do - post :create, project_partner: { leader_org: @project_partner.leader_org, organisation_id: @project_partner.organisation_id, project_id: @project_partner.project_id } - end - - assert_redirected_to project_partner_path(assigns(:project_partner)) - end - - test "should show project_partner" do - get :show, id: @project_partner - assert_response :success - end - - test "should get edit" do - get :edit, id: @project_partner - assert_response :success - end - - test "should update project_partner" do - put :update, id: @project_partner, project_partner: { leader_org: @project_partner.leader_org, organisation_id: @project_partner.organisation_id, project_id: @project_partner.project_id } - assert_redirected_to project_partner_path(assigns(:project_partner)) - end - - test "should destroy project_partner" do - assert_difference('ProjectPartner.count', -1) do - delete :destroy, id: @project_partner - end - - assert_redirected_to project_partners_path - end -=end -end diff --git a/test/functional/projects_controller_test.rb b/test/functional/projects_controller_test.rb deleted file mode 100644 index 260bdb7..0000000 --- a/test/functional/projects_controller_test.rb +++ /dev/null @@ -1,48 +0,0 @@ -require 'test_helper' - -class ProjectsControllerTest < ActionDispatch::IntegrationTest -=begin - - test "should get index" do - get :index - assert_response :success - assert_not_nil assigns(:projects) - end - - test "should get new" do - get :new - assert_response :success - end - - test "should create project" do - assert_difference('Project.count') do - post :create, project: { dmptemplate_id: @project.dmptemplate_id, locked: @project.locked, note: @project.note, title: @project.title } - end - - assert_redirected_to project_path(assigns(:project)) - end - - test "should show project" do - get :show, id: @project - assert_response :success - end - - test "should get edit" do - get :edit, id: @project - assert_response :success - end - - test "should update project" do - put :update, id: @project, project: { dmptemplate_id: @project.dmptemplate_id, locked: @project.locked, note: @project.note, title: @project.title } - assert_redirected_to project_path(assigns(:project)) - end - - test "should destroy project" do - assert_difference('Project.count', -1) do - delete :destroy, id: @project - end - - assert_redirected_to projects_path - end -=end -end diff --git a/test/functional/question_themes_controller_test.rb b/test/functional/question_themes_controller_test.rb deleted file mode 100644 index e4d015f..0000000 --- a/test/functional/question_themes_controller_test.rb +++ /dev/null @@ -1,51 +0,0 @@ -require 'test_helper' - -class QuestionThemesControllerTest < ActionController::TestCase -=begin - setup do - @question_theme = question_themes(:one) - end - - test "should get index" do - get :index - assert_response :success - assert_not_nil assigns(:question_themes) - end - - test "should get new" do - get :new - assert_response :success - end - - test "should create question_theme" do - assert_difference('QuestionTheme.count') do - post :create, question_theme: { question_id: @question_theme.question_id, theme_id: @question_theme.theme_id } - end - - assert_redirected_to question_theme_path(assigns(:question_theme)) - end - - test "should show question_theme" do - get :show, id: @question_theme - assert_response :success - end - - test "should get edit" do - get :edit, id: @question_theme - assert_response :success - end - - test "should update question_theme" do - put :update, id: @question_theme, question_theme: { question_id: @question_theme.question_id, theme_id: @question_theme.theme_id } - assert_redirected_to question_theme_path(assigns(:question_theme)) - end - - test "should destroy question_theme" do - assert_difference('QuestionTheme.count', -1) do - delete :destroy, id: @question_theme - end - - assert_redirected_to question_themes_path - end -=end -end diff --git a/test/functional/questions_controller_test.rb b/test/functional/questions_controller_test.rb deleted file mode 100644 index 6ecfde8..0000000 --- a/test/functional/questions_controller_test.rb +++ /dev/null @@ -1,51 +0,0 @@ -require 'test_helper' - -class QuestionsControllerTest < ActionController::TestCase -=begin - setup do - @question = questions(:one) - end - - test "should get index" do - get :index - assert_response :success - assert_not_nil assigns(:questions) - end - - test "should get new" do - get :new - assert_response :success - end - - test "should create question" do - assert_difference('Question.count') do - post :create, question: { default_value: @question.default_value, dependency_id: @question.dependency_id, dependency_text: @question.dependency_text, guidance: @question.guidance, order: @question.order, parent_id: @question.parent_id, suggested_answer: @question.suggested_answer, text: @question.text, type: @question.type, section_id: @question.section_id } - end - - assert_redirected_to question_path(assigns(:question)) - end - - test "should show question" do - get :show, id: @question - assert_response :success - end - - test "should get edit" do - get :edit, id: @question - assert_response :success - end - - test "should update question" do - put :update, id: @question, question: { default_value: @question.default_value, dependency_id: @question.dependency_id, dependency_text: @question.dependency_text, guidance: @question.guidance, order: @question.order, parent_id: @question.parent_id, suggested_answer: @question.suggested_answer, text: @question.text, type: @question.type, section_id: @question.section_id } - assert_redirected_to question_path(assigns(:question)) - end - - test "should destroy question" do - assert_difference('Question.count', -1) do - delete :destroy, id: @question - end - - assert_redirected_to questions_path - end -=end -end diff --git a/test/functional/sections_controller_test.rb b/test/functional/sections_controller_test.rb deleted file mode 100644 index a3847e3..0000000 --- a/test/functional/sections_controller_test.rb +++ /dev/null @@ -1,51 +0,0 @@ -require 'test_helper' - -class SectionsControllerTest < ActionController::TestCase -=begin - setup do - @section = sections(:one) - end - - test "should get index" do - get :index - assert_response :success - assert_not_nil assigns(:sections) - end - - test "should get new" do - get :new - assert_response :success - end - - test "should create section" do - assert_difference('Section.count') do - post :create, section: { organisation_id: @section.organisation_id, description: @section.description, order: @section.order, title: @section.title, version_id: @section.version_id } - end - - assert_redirected_to section_path(assigns(:section)) - end - - test "should show section" do - get :show, id: @section - assert_response :success - end - - test "should get edit" do - get :edit, id: @section - assert_response :success - end - - test "should update section" do - put :update, id: @section, section: { organisation_id: @section.organisation_id, description: @section.description, order: @section.order, title: @section.title, version_id: @section.version_id } - assert_redirected_to section_path(assigns(:section)) - end - - test "should destroy section" do - assert_difference('Section.count', -1) do - delete :destroy, id: @section - end - - assert_redirected_to sections_path - end -=end -end diff --git a/test/functional/static_pages_controller_test.rb b/test/functional/static_pages_controller_test.rb index 3450cc5..11efee1 100644 --- a/test/functional/static_pages_controller_test.rb +++ b/test/functional/static_pages_controller_test.rb @@ -3,17 +3,31 @@ include Devise::Test::IntegrationHelpers setup do - @project = Project.first + @public_project = Project.create!({title: 'Public Test Project', + dmptemplate: Dmptemplate.first, + organisation: Organisation.first, + visibility: :publicly_visible}) + end + + # ---------------------------------------------------------- + test "should only return plans with public visibility" do + get public_plans_path(locale: I18n.locale) - @test_visibility = Visibility.find_by(name: 'test') - @public_visibility = Visibility.find_by(name: 'public') + assert_response :success + assert_not_nil assigns(:projects) + + all_public = true + + assigns(:projects).each do |project| + all_public = false unless project.publicly_visible? + end + + assert all_public, "expected all of the plans to have public visibility!" end # ---------------------------------------------------------- test "should export the publicly available plan" do - @project.visibility = @public_visibility - @project.save! - + # get public_export_path(locale: I18n.locale, id: @project) # Should be redirected to the plans controller's export function @@ -28,21 +42,21 @@ # ---------------------------------------------------------- test "should NOT export a non-public plan to unauthorized users" do # Set the is_public flag to false and try to access it when not logged in - @project.visibility = @test_visibility - @project.save! + @public_project.visibility = :privately_visible + @public_project.save! - get public_export_path(locale: I18n.locale, id: @project) + get public_export_path(locale: I18n.locale, id: @public_project) assert_redirected_to "#{public_plans_path}", "expected to be redirected to the home page!" assert_equal I18n.t('helpers.settings.plans.errors.no_access_account'), flash[:notice], "Expected an unauthorized message when trying to export a plan (via the public_export route) when the plan is not actually public" # Set the is_public flag to false and assign ownership to a different user and then try to access it as a non-owner - @project.assign_creator(User.last) - @project.save! + @public_project.assign_creator(User.last) + @public_project.save! sign_in User.first - get public_export_path(locale: I18n.locale, id: @project) + get public_export_path(locale: I18n.locale, id: @public_project) assert_redirected_to "#{public_plans_path}", "expected to be redirected to the home page!" assert_equal I18n.t('helpers.settings.plans.errors.no_access_account'), flash[:notice], "Expected an unauthorized message when trying to export a plan (via the public_export route) when the plan is not actually public" diff --git a/test/functional/themes_controller_test.rb b/test/functional/themes_controller_test.rb deleted file mode 100644 index 3bae2d6..0000000 --- a/test/functional/themes_controller_test.rb +++ /dev/null @@ -1,51 +0,0 @@ -require 'test_helper' - -class ThemesControllerTest < ActionController::TestCase -=begin - setup do - @theme = themes(:one) - end - - test "should get index" do - get :index - assert_response :success - assert_not_nil assigns(:themes) - end - - test "should get new" do - get :new - assert_response :success - end - - test "should create theme" do - assert_difference('Theme.count') do - post :create, theme: { description: @theme.description, title: @theme.title } - end - - assert_redirected_to theme_path(assigns(:theme)) - end - - test "should show theme" do - get :show, id: @theme - assert_response :success - end - - test "should get edit" do - get :edit, id: @theme - assert_response :success - end - - test "should update theme" do - put :update, id: @theme, theme: { description: @theme.description, title: @theme.title } - assert_redirected_to theme_path(assigns(:theme)) - end - - test "should destroy theme" do - assert_difference('Theme.count', -1) do - delete :destroy, id: @theme - end - - assert_redirected_to themes_path - end -=end -end diff --git a/test/functional/user_org_roles_controller_test.rb b/test/functional/user_org_roles_controller_test.rb deleted file mode 100644 index 8412e88..0000000 --- a/test/functional/user_org_roles_controller_test.rb +++ /dev/null @@ -1,51 +0,0 @@ -require 'test_helper' - -class UserOrgRolesControllerTest < ActionController::TestCase -=begin - setup do - @user_role = user_org_roles(:one) - end - - test "should get index" do - get :index - assert_response :success - assert_not_nil assigns(:user_org_roles) - end - - test "should get new" do - get :new - assert_response :success - end - - test "should create user_org_role" do - assert_difference('UserOrgRole.count') do - post :create, user_org_role: { organisation_id: @user_org_role.organisation_id, user_id: @user_org_role.user_id, user_role_type_id: @user_org_role.user_role_type_id } - end - - assert_redirected_to user_org_role_path(assigns(:user_org_role)) - end - - test "should show user_org_role" do - get :show, id: @user_org_role - assert_response :success - end - - test "should get edit" do - get :edit, id: @user_org_role - assert_response :success - end - - test "should update user_org_role" do - put :update, id: @user_org_role, user_org_role: { organisation_id: @user_org_role.organisation_id, user_id: @user_org_role.user_id, user_role_type_id: @user_org_role.user_role_type_id } - assert_redirected_to user_org_role_path(assigns(:user_org_role)) - end - - test "should destroy user_org_role" do - assert_difference('UserOrgRole.count', -1) do - delete :destroy, id: @user_org_role - end - - assert_redirected_to user_org_roles_path - end -=end -end diff --git a/test/functional/user_role_types_controller_test.rb b/test/functional/user_role_types_controller_test.rb deleted file mode 100644 index 5686f79..0000000 --- a/test/functional/user_role_types_controller_test.rb +++ /dev/null @@ -1,51 +0,0 @@ -require 'test_helper' - -class UserRoleTypesControllerTest < ActionController::TestCase -=begin - setup do - @user_role_type = user_role_types(:one) - end - - test "should get index" do - get :index - assert_response :success - assert_not_nil assigns(:user_role_types) - end - - test "should get new" do - get :new - assert_response :success - end - - test "should create user_role_type" do - assert_difference('UserRoleType.count') do - post :create, user_role_type: { description: @user_role_type.description, name: @user_role_type.name } - end - - assert_redirected_to user_role_type_path(assigns(:user_role_type)) - end - - test "should show user_role_type" do - get :show, id: @user_role_type - assert_response :success - end - - test "should get edit" do - get :edit, id: @user_role_type - assert_response :success - end - - test "should update user_role_type" do - put :update, id: @user_role_type, user_role_type: { description: @user_role_type.description, name: @user_role_type.name } - assert_redirected_to user_role_type_path(assigns(:user_role_type)) - end - - test "should destroy user_role_type" do - assert_difference('UserRoleType.count', -1) do - delete :destroy, id: @user_role_type - end - - assert_redirected_to user_role_types_path - end -=end -end diff --git a/test/functional/user_statuses_controller_test.rb b/test/functional/user_statuses_controller_test.rb deleted file mode 100644 index 7487419..0000000 --- a/test/functional/user_statuses_controller_test.rb +++ /dev/null @@ -1,51 +0,0 @@ -require 'test_helper' - -class UserStatusesControllerTest < ActionController::TestCase -=begin - setup do - @user_status = user_statuses(:one) - end - - test "should get index" do - get :index - assert_response :success - assert_not_nil assigns(:user_statuses) - end - - test "should get new" do - get :new - assert_response :success - end - - test "should create user_status" do - assert_difference('UserStatus.count') do - post :create, user_status: { description: @user_status.description, name: @user_status.name } - end - - assert_redirected_to user_status_path(assigns(:user_status)) - end - - test "should show user_status" do - get :show, id: @user_status - assert_response :success - end - - test "should get edit" do - get :edit, id: @user_status - assert_response :success - end - - test "should update user_status" do - put :update, id: @user_status, user_status: { description: @user_status.description, name: @user_status.name } - assert_redirected_to user_status_path(assigns(:user_status)) - end - - test "should destroy user_status" do - assert_difference('UserStatus.count', -1) do - delete :destroy, id: @user_status - end - - assert_redirected_to user_statuses_path - end -=end -end diff --git a/test/functional/user_types_controller_test.rb b/test/functional/user_types_controller_test.rb deleted file mode 100644 index 267ef27..0000000 --- a/test/functional/user_types_controller_test.rb +++ /dev/null @@ -1,51 +0,0 @@ -require 'test_helper' - -class UserTypesControllerTest < ActionController::TestCase -=begin - setup do - @user_type = user_types(:one) - end - - test "should get index" do - get :index - assert_response :success - assert_not_nil assigns(:user_types) - end - - test "should get new" do - get :new - assert_response :success - end - - test "should create user_type" do - assert_difference('UserType.count') do - post :create, user_type: { description: @user_type.description, name: @user_type.name } - end - - assert_redirected_to user_type_path(assigns(:user_type)) - end - - test "should show user_type" do - get :show, id: @user_type - assert_response :success - end - - test "should get edit" do - get :edit, id: @user_type - assert_response :success - end - - test "should update user_type" do - put :update, id: @user_type, user_type: { description: @user_type.description, name: @user_type.name } - assert_redirected_to user_type_path(assigns(:user_type)) - end - - test "should destroy user_type" do - assert_difference('UserType.count', -1) do - delete :destroy, id: @user_type - end - - assert_redirected_to user_types_path - end -=end -end diff --git a/test/functional/versions_controller_test.rb b/test/functional/versions_controller_test.rb deleted file mode 100644 index a3c4be7..0000000 --- a/test/functional/versions_controller_test.rb +++ /dev/null @@ -1,51 +0,0 @@ -require 'test_helper' - -class VersionsControllerTest < ActionController::TestCase -=begin - setup do - @version = versions(:one) - end - - test "should get index" do - get :index - assert_response :success - assert_not_nil assigns(:versions) - end - - test "should get new" do - get :new - assert_response :success - end - - test "should create version" do - assert_difference('Version.count') do - post :create, version: { description: @version.description, order: @version.order, published: @version.published, title: @version.title } - end - - assert_redirected_to version_path(assigns(:version)) - end - - test "should show version" do - get :show, id: @version - assert_response :success - end - - test "should get edit" do - get :edit, id: @version - assert_response :success - end - - test "should update version" do - put :update, id: @version, version: { description: @version.description, order: @version.order, published: @version.published, title: @version.title } - assert_redirected_to version_path(assigns(:version)) - end - - test "should destroy version" do - assert_difference('Version.count', -1) do - delete :destroy, id: @version - end - - assert_redirected_to versions_path - end -=end -end diff --git a/test/test_helper.rb b/test/test_helper.rb index 0adb64e..11bf531 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -60,12 +60,7 @@ number: 1 })] }) - -# template.phases << Phase.new({ -# title: 'Phase 1', -# number: 1 -# }) - + template.phases.first.versions << Version.new({ title: 'Version 1', number: 1, diff --git a/test/unit/admin_user_test.rb b/test/unit/admin_user_test.rb deleted file mode 100644 index 23a3cc8..0000000 --- a/test/unit/admin_user_test.rb +++ /dev/null @@ -1,7 +0,0 @@ -require 'test_helper' - -class AdminUserTest < ActiveSupport::TestCase - # test "the truth" do - # assert true - # end -end diff --git a/test/unit/answer_test.rb b/test/unit/answer_test.rb index 04cf87a..6e05a24 100644 --- a/test/unit/answer_test.rb +++ b/test/unit/answer_test.rb @@ -15,6 +15,8 @@ project.dmptemplate = template project.save! + @plan = project.plans.first + qs = template.phases.first.versions.first.sections.first.questions @text_area_question = qs.select{ |q| q.question_format == QuestionFormat.find_by(title: 'Text Area' ) }.first @text_field_question = qs.select{ |q| q.question_format == QuestionFormat.find_by(title: 'Text Field' ) }.first @@ -24,35 +26,30 @@ @multi_select_box_question = qs.select{ |q| q.question_format == QuestionFormat.find_by(title: 'Multi Select Box' ) }.first end -=begin # --------------------------------------------------- test "required fields are required" do assert_not Answer.new.valid? - assert_not Answer.new(user: @user).valid? - assert_not Answer.new(plan: @plan).valid? - assert_not Answer.new(question: @text_area_question).valid? - assert_not Answer.new(user: @user, plan: @plan).valid? - assert_not Answer.new(user: @user, question: @text_area_question).valid? - assert_not Answer.new(plan: @plan, question: @text_area_question).valid? + assert_not Answer.new(user: @user, question: @text_area_question).valid?, "expected the 'text' field to be required" + assert_not Answer.new(plan: @plan, question: @text_area_question, text: 'Testing').valid?, "expected the 'user' field to be required" + assert_not Answer.new(user: @user, question: @text_area_question, text: 'Testing').valid?, "expected the 'plan' field to be required" + assert_not Answer.new(user: @user, plan: @plan, text: 'Testing').valid?, "expected the 'question' field to be required" # Ensure the bar minimum and complete versions are valid - assert Answer.new(user: @user, plan: @plan, question: @text_area_question).valid? + a = Answer.new(user: @user, plan: @plan, question: @text_area_question, text: 'Testing') + assert a.valid?, "expected the 'text', 'plan', 'user' and 'question' fields to be enough to create an Answer! - #{a.errors.map{|f, m| f.to_s + ' ' + m}.join(', ')}" end # --------------------------------------------------- test "cannot have multiple answers to the same question within a plan" do Answer.create(user: @user, plan: @plan, question: @text_area_question, text: 'Tested ABC') - assert_not Answer.new(user: @user, plan: @plan, question: @text_area_question).valid? - -puts @plan.answers.inspect - - assert_not Answer.new(user: @user, plan: @plan, question: @text_area_question, text: 'ABCD').valid? + + assert_not Answer.new(user: @user, plan: @plan, question: @text_area_question, text: 'Another answer to the same question!').valid?, "expected to NOT be able to add an answer to a question that already has an answer!" end # --------------------------------------------------- test "can CRUD answers for text based questions" do [@text_area_question, @text_field_question].each do |q| - answr = Answer.new(user: @user, plan: @plan, question: q, text: 'Tested ABC') + answr = Answer.create(user: @user, plan: @plan, question: q, text: 'Tested ABC') assert_not answr.id.nil?, "was expecting to be able to create a new Answer for a #{q.question_format.title} question: #{answr.errors.map{|f, m| f.to_s + ' ' + m}.join(', ')}" answr.text = 'Testing an update' @@ -63,6 +60,5 @@ assert answr.destroy!, "Was unable to delete the Answer for a #{q.question_format.title} question!" end end -=end end diff --git a/test/unit/comment_test.rb b/test/unit/comment_test.rb index 9575e6c..510845f 100644 --- a/test/unit/comment_test.rb +++ b/test/unit/comment_test.rb @@ -1,7 +1,50 @@ -require 'test_helper' - -class CommentTest < ActiveSupport::TestCase - # test "the truth" do - # assert true - # end -end +require 'test_helper' + +class CommentTest < ActiveSupport::TestCase + + setup do + @user = User.last + + # generate a template and plan + template = generate_complete_template + + project = Project.new({ + title: 'Test Project', + organisation: @user.organisation + }) + project.dmptemplate = template + project.save! + + @plan = project.plans.first + + qs = template.phases.first.versions.first.sections.first.questions + @text_area_question = qs.select{ |q| q.question_format == QuestionFormat.find_by(title: 'Text Area' ) }.first + end + + # --------------------------------------------------- + test "required fields are required" do + assert_not Comment.new.valid? + assert_not Comment.new(user: @user, question: @text_area_question).valid?, "expected the 'text' field to be required" + assert_not Comment.new(plan: @plan, question: @text_area_question, text: 'Testing').valid?, "expected the 'user' field to be required" + assert_not Comment.new(user: @user, question: @text_area_question, text: 'Testing').valid?, "expected the 'plan' field to be required" + assert_not Comment.new(user: @user, plan: @plan, text: 'Testing').valid?, "expected the 'question' field to be required" + + # Ensure the bar minimum and complete versions are valid + a = Comment.new(user: @user, plan: @plan, question: @text_area_question, text: 'Testing') + assert a.valid?, "expected the 'text', 'plan', 'user' and 'question' fields to be enough to create an Comment! - #{a.errors.map{|f, m| f.to_s + ' ' + m}.join(', ')}" + end + + # --------------------------------------------------- + test "can CRUD Comment" do + cmnt = Comment.create(user: @user, plan: @plan, question: @text_area_question, text: 'Tested ABC') + assert_not cmnt.id.nil?, "was expecting to be able to create a new Comment: #{cmnt.errors.map{|f, m| f.to_s + ' ' + m}.join(', ')}" + + cmnt.text = 'Testing an update' + cmnt.save! + cmnt.reload + assert_equal 'Testing an update', cmnt.text, "Was expecting to be able to update the text of the Comment!" + + assert cmnt.destroy!, "Was unable to delete the Comment!" + end + +end diff --git a/test/unit/dmptemplate_test.rb b/test/unit/dmptemplate_test.rb index 595d984..6e362fd 100644 --- a/test/unit/dmptemplate_test.rb +++ b/test/unit/dmptemplate_test.rb @@ -4,13 +4,14 @@ setup do @template = Dmptemplate.first + + @organisation = Organisation.first end def settings(extras = {}) - { - margin: (@margin || { top: 10, bottom: 10, left: 10, right: 10 }), - font_face: (@font_face || Settings::Dmptemplate::VALID_FONT_FACES.first), - font_size: (@font_size || 11) + {margin: (@margin || { top: 10, bottom: 10, left: 10, right: 10 }), + font_face: (@font_face || Settings::Dmptemplate::VALID_FONT_FACES.first), + font_size: (@font_size || 11) }.merge(extras) end @@ -18,13 +19,31 @@ Settings::Dmptemplate::DEFAULT_SETTINGS[:formatting] end - # ---------- settings ---------- + # --------------------------------------------------- + test "required fields are required" do + assert_not Dmptemplate.new.valid? + assert_not Dmptemplate.new(title: 'Testing tmeplate').valid?, "expected the 'title' field to be required" + assert_not Dmptemplate.new(organisation: @organisation).valid?, "expected the 'organisation' field to be required" + + # Ensure the bar minimum and complete versions are valid + a = Dmptemplate.new(organisation: @organisation, title: 'Testing tmeplate') + assert a.valid?, "expected the 'title' and 'organisation' fields to be enough to create an Dmptemplate! - #{a.errors.map{|f, m| f.to_s + ' ' + m}.join(', ')}" + end + + # --------------------------------------------------- + test "to_s method returns the title" do + assert_equal @template.title, @template.to_s + end + - test "settings should use defaults if none defined" do + # ---------- settings ---------- + # --------------------------------------------------- + test "settings should use defaults if none are defined" do assert(!@template.settings(:export).value?) assert_equal(default_formatting, @template.settings(:export).formatting) end + # --------------------------------------------------- test "settings should use defined valid settings" do @template.settings(:export).formatting = settings @template.save! @@ -34,6 +53,7 @@ assert_not_equal(default_formatting, @template.settings(:export).formatting) end + # --------------------------------------------------- test "setting negative margin should not be valid" do @margin = { top: -10, bottom: 10, left: 10, right: 10 } @@ -49,6 +69,7 @@ assert_equal(default_formatting, @template.settings(:export).formatting) end + # --------------------------------------------------- test "setting unknown margin should not be valid" do @margin = { top: 10, bottom: 10, left: 10, right: 10, top_left: 10 } @@ -64,6 +85,7 @@ assert_equal(default_formatting, @template.settings(:export).formatting) end + # --------------------------------------------------- test "setting negative font-size should not be valid" do @font_size = -11 @@ -80,6 +102,7 @@ assert_equal(default_formatting, @template.settings(:export).formatting) end + # --------------------------------------------------- test "setting unknown key should not be valid" do @template.settings(:export).formatting = settings(foo: :bar) @@ -94,6 +117,7 @@ assert_equal(default_formatting, @template.settings(:export).formatting) end + # --------------------------------------------------- test "not setting font_face should not be valid" do @template.settings(:export).formatting = settings.reject {|k,v| k == :font_face } @@ -108,6 +132,7 @@ assert_equal(default_formatting, @template.settings(:export).formatting) end + # --------------------------------------------------- test "not setting font_size should not be valid" do @template.settings(:export).formatting = settings.reject {|k,v| k == :font_size } @@ -122,6 +147,7 @@ assert_equal(default_formatting, @template.settings(:export).formatting) end + # --------------------------------------------------- test "not setting margin should not be valid" do @template.settings(:export).formatting = settings.reject {|k,v| k == :margin } @@ -136,6 +162,7 @@ assert_equal(default_formatting, @template.settings(:export).formatting) end + # --------------------------------------------------- test "setting non-hash as margin should not be valid" do @margin = :foo @@ -152,6 +179,7 @@ assert_equal(default_formatting, @template.settings(:export).formatting) end + # --------------------------------------------------- test "setting non-integer as font_size should not be valid" do @font_size = "foo" @@ -168,6 +196,7 @@ assert_equal(default_formatting, @template.settings(:export).formatting) end + # --------------------------------------------------- test "setting non-string as font_face should not be valid" do @font_face = 1 @@ -184,6 +213,7 @@ assert_equal(default_formatting, @template.settings(:export).formatting) end + # --------------------------------------------------- test "setting unknown string as font_face should not be valid" do @font_face = 'Monaco, Monospace, Sans-Serif' @@ -200,64 +230,6 @@ assert_equal(default_formatting, @template.settings(:export).formatting) end - # ---------- templates_org_type ---------- - test "templates_org_type returns all published" do - OrganisationType.find_each do |org_type| - result_templates = Dmptemplate.templates_org_type(org_type.name) - my_list = Array.new - org_type.organisations.each do |org| - my_list += org.dmptemplates - end - my_list.each do |template| - if template.published - assert_includes(result_templates, template, "Template: #{template.title}} of type #{org_type.name}, not returned by templates_org_type") - end - end - end - end - - # ---------- funders_templates ---------- - test "funders_templates returns all funder organisation templates" do - result_templates = Dmptemplate.funders_templates - funder_templates = OrganisationType.first.organisations do |org| - org.dmptemplates.each do |template| - assert_includes( result_templates, template, "Funder Template: #{template.title} not included in result of funders_templates") - end - end - end - - # ---------- own_institutional_templates ---------- - test "own_institutional_templates returns all templates belonging to given org_id" do - Organisation.find_each do |org| - result_templates = Dmptemplate.own_institutional_templates(org.id) - org.dmptemplates.each do |template| - assert_includes(result_templates, template, "Template: #{template.title} not returned by own_institutional_templates") - end - end - end - - # ---------- funders_and_own_templates ---------- - test "funders_and_own_templates returns all funder and own given org_id templates" do - Organisation.find_each do |org| - result_templates = Dmptemplate.funders_and_own_templates(org.id) - org.dmptemplates.each do |template| - assert_includes(result_templates, template, "Template #{template.title} not returned by funders and own templates") - end - end - funder_templates = OrganisationType.first.organisations do |org| - org.dmptemplates.each do |template| - assert_includes( result_templates, template, "Funder Template: #{template.title} not included in result of funders_and_own_templates") - end - end - end - - # ---------- org_type ---------- - test "org_type properly returns the name of the template's organisation's type" do - Dmptemplate.find_each do |template| - assert_equal( template.org_type, template.organisation.organisation_type.name, "Template: #{template.title} returned #{template.org_type}, instead of #{template.organisation.organisation_type.name}") - end - end - # ---------- has_customisations? ---------- test "has_customisations? correctly identifies if a given org has customised the template" do # TODO: Impliment after understanding has_customisations @@ -275,5 +247,40 @@ end end + # --------------------------------------------------- + test "can CRUD Template" do + tmplt = Dmptemplate.create(organisation: @organisation, title: 'Testing tmeplate') + assert_not tmplt.id.nil?, "was expecting to be able to create a new Dmptemplate!" + 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 Dmptemplate!" + + assert tmplt.destroy!, "Was unable to delete the Dmptemplate!" + 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 Project" do + project = Project.new(title: 'Test Project', organisation: @organisation) + verify_has_many_relationship(@template, project, @template.projects.count) + end + + # --------------------------------------------------- + test "can manage has_many relationship with GuidanceGroup" do + grp = GuidanceGroup.new(name: 'Test Group', organisation: @organisation) + verify_has_many_relationship(@template, grp, @template.guidance_groups.count) + end + + # --------------------------------------------------- + test "can manage belongs_to relationship with Organisation" do + verify_belongs_to_relationship(@template, @organisation) + end + end diff --git a/test/unit/exported_plan_test.rb b/test/unit/exported_plan_test.rb new file mode 100644 index 0000000..00ef9cb --- /dev/null +++ b/test/unit/exported_plan_test.rb @@ -0,0 +1,71 @@ +require 'test_helper' + +class ExportedPlanTest < ActiveSupport::TestCase + + setup do + @user = User.last + + # generate a template and plan + template = generate_complete_template + + project = Project.new({ + title: 'Test Project', + organisation: @user.organisation + }) + project.dmptemplate = template + project.save! + + @plan = project.plans.first + + @exported = ExportedPlan.create(user: @user, plan: @plan, format: ExportedPlan::VALID_FORMATS.first) + end + + # --------------------------------------------------- + test "required fields are required" do + assert_not ExportedPlan.new.valid? + assert_not ExportedPlan.new(format: ExportedPlan::VALID_FORMATS.last).valid?, "expected the 'plan' field to be required" + assert_not ExportedPlan.new(plan: @plan).valid?, "expected the 'format' field to be required" + + # Ensure the bar minimum and complete versions are valid + a = ExportedPlan.new(plan: @plan, format: ExportedPlan::VALID_FORMATS.last) + assert a.valid?, "expected the 'plan', 'user' and 'format' fields to be enough to create an ExportedPlan! - #{a.errors.map{|f, m| f.to_s + ' ' + m}.join(', ')}" + end + + # --------------------------------------------------- + test "as_csv" do + + end + + # --------------------------------------------------- + test "as_txt" do + + end + + # --------------------------------------------------- + test "can CRUD ExportedPlan" do + ExportedPlan::VALID_FORMATS.each do |vf| + ep = ExportedPlan.create(user: @user, plan: @plan, format: vf) + assert_not ep.id.nil?, "was expecting to be able to create a new ExportedPlan: #{ep.errors.map{|f, m| f.to_s + ' ' + m}.join(', ')}" + + expected = (vf == ExportedPlan::VALID_FORMATS.last ? ExportedPlan::VALID_FORMATS.first : ExportedPlan::VALID_FORMATS.last) + + ep.format = expected + ep.save! + ep.reload + assert_equal expected, ep.format, "Was expecting to be able to update the format of the ExportedPlan!" + + assert ep.destroy!, "Was unable to delete the ExportedPlan!" + end + end + + # --------------------------------------------------- + test "can manage belongs_to relationship with Plan" do + verify_belongs_to_relationship(@exported, Plan.last) + end + + # --------------------------------------------------- + test "can manage belongs_to relationship with User" do + verify_belongs_to_relationship(@exported, User.last) + end + +end diff --git a/test/unit/guidance_test.rb b/test/unit/guidance_test.rb deleted file mode 100644 index 9091309..0000000 --- a/test/unit/guidance_test.rb +++ /dev/null @@ -1,201 +0,0 @@ -require 'test_helper' - -class GuidanceTest < ActiveSupport::TestCase - - setup do - @user_one = User.first - @user_two = User.order(surname: :desc).first - @user_three = User.last - - @org_type = OrganisationType.first - - @organisations = Organisation.all - end - - # ---------- can_view? ---------- - # ensure that the can_view? function returns true all viewable guidances - # should return true for groups owned by funders - # should return true for groups owned by DCC - # should return true for groups owned by the user's organisation - # should not return true for an organisation outwith those above - test "DCC guidances should be viewable" do -=begin - guidance_groups(:dcc_guidance_group_1).guidances.each do |guidance| - assert Guidance.can_view?(@user_one, guidance.id) - end -=end - end - - test "Funder guidances should be viewable" do -=begin - assert Guidance.can_view?(@user_one, guidances(:ahrc_funder_guidance).id) - assert Guidance.can_view?(@user_one, guidances(:bbsrc_funder_guidance).id) -=end - end - - - test "User's organisation guidances should be viewable" do -=begin - assert Guidance.can_view?(@user_one, guidances(:aru_institution_guidance).id) , "user_one cannot view aru_institution_guidance" - - assert Guidance.can_view?(@user_two, guidances(:au_institution_guidance_1).id), "user_two cannot view au_..._1" - assert Guidance.can_view?(@user_two, guidances(:au_institution_guidance_2).id), "user_two cannot view au_..._2" - - assert Guidance.can_view?(@user_three, guidances(:bu_institution_guidance_1).id), "user_three cannot view bu_..._1" - assert Guidance.can_view?(@user_three, guidances(:bu_institution_guidance_2).id), "user_three cannot view bu_..._2" -=end - end - - test "No other organisations's guidances should be viewable" do -=begin - # TOOD: add more fixtures with new types of guidances(i.e. not institution) - # and add test cases - assert_not Guidance.can_view?(@user_one, guidances(:au_institution_guidance_1).id) - assert_not Guidance.can_view?(@user_one, guidances(:au_institution_guidance_2).id) - assert_not Guidance.can_view?(@user_one, guidances(:bu_institution_guidance_1).id) - assert_not Guidance.can_view?(@user_one, guidances(:bu_institution_guidance_2).id) - - assert_not Guidance.can_view?(@user_two, guidances(:aru_institution_guidance).id) - assert_not Guidance.can_view?(@user_two, guidances(:bu_institution_guidance_1).id) - assert_not Guidance.can_view?(@user_two, guidances(:bu_institution_guidance_2).id) - - assert_not Guidance.can_view?(@user_three, guidances(:aru_institution_guidance).id) - assert_not Guidance.can_view?(@user_three, guidances(:au_institution_guidance_1).id) - assert_not Guidance.can_view?(@user_three, guidances(:au_institution_guidance_2).id) -=end - end - -# ---------- all_viewable ---------- - # ensure that the all_viewable function returns all viewable guidances - # should return true for groups owned by funders - # should return true for groups owned by DCC - # should return true for groups owned by the user's organisation - # should not return true for an organisation outwith those above - test "all_viewable returns all DCC guidances" do -=begin - all_viewable_guidances = Guidance.all_viewable(@user_one) - @organisations.first.guidance_groups.each do |group| - group.guidances.each do |guidance| - assert_includes(all_viewable_guidances, guidance) - end - end -=end - end - - test "all_viewable returns all funder guidances" do -=begin - all_viewable_guidances = Guidance.all_viewable(@user_one) - guidance_groups(:funder_guidance_group_1).guidances.each do |guidance| - assert_includes(all_viewable_guidances, guidance) - end - guidance_groups(:funder_guidance_group_2).guidances.each do |guidance| - assert_includes(all_viewable_guidances, guidance) - end -=end - end - - test "all_viewable returns all of a user's organisations's guidances" do -=begin - all_viewable_guidances_one = Guidance.all_viewable(@user_one) - @organisations.first.guidance_groups.each do |group| - group.guidances.each do |guidance| - assert_includes(all_viewable_guidances_one, guidance) - end - end - - all_viewable_guidances_two = Guidance.all_viewable(@user_two) - @organisations[1].guidance_groups.each do |group| - group.guidances.each do |guidance| - assert_includes(all_viewable_guidances_two, guidance) - end - end - - all_viewable_guidances_three = Guidance.all_viewable(@user_three) - @organisations.last.guidance_groups.each do |group| - group.guidances.each do |guidance| - assert_includes(all_viewable_guidances_three, guidance) - end - end -=end - end - - - test "all_viewable does not return any other organisation's guidance" do -=begin - # TODO: Add in a suitable test. should we check for non-institutions? - all_viewable_guidances = Guidance.all_viewable(@user_one) - # remove all of the user's organisation - # remove all of each funder's organisations - # remove each of the dcc's organisations - # check if nill - all_viewable_guidances.delete_if do |guidance| - guidance.guidance_groups.each do |group| - if group.organisation.id == organisations(:dcc).id - true - elsif group.organisation.organisation_type.id == organisation_types(:funder).id - true - elsif group.organisation.id == @user_one.organisations.first.id - true - else - false - end - end - end - assert_empty(all_viewable_guidances, "there must not be any guidances which are not funders, DCC, or our own organisation") -=end - end - - # ---------- in_group_belonging_to? ---------- - test "in_group_belonging_to correctly identifies parent orgs" do -=begin - # test that the association works for all correct usages - Guidance.all.each do |guidance| - guidance.guidance_groups.each do |group| - assert(guidance.in_group_belonging_to?(group.organisation.id), "Guidance: #{guidance.text} should belong to organisation #{group.organisation.name}") - end - end -=end - end - - test "in_group_belonging_to rejects non-parent orgs" do -=begin - # test that in_group_belonging_to rejects a few interesting organisation-guidance pairs - assert_not(guidances(:related_policies).in_group_belonging_to?(organisations(:ahrc)), "Organisation ahrc does not own guidance: related policies") - assert_not(guidances(:ahrc_funder_guidance).in_group_belonging_to?(organisations(:dcc)), "Organisation dcc does not own guidance: ahrc_funder_guidance") -=end - end - - # ---------- by_organisation ---------- - test "by_organisation correctly returns all guidance belonging to a given org" do -=begin - Organisation.all.each do |org| - org_guidance = Guidance.by_organisation(org) - org.guidance_groups.each do |group| - group.guidances.each do |guidance| - assert_includes(org_guidance, guidance, "Guidance #{guidance.text} should belong to organisation: #{org.name}") - end - end - end -=end - end - - # ---------- get_guidance_group_templates ---------- - ## the main function is completely bugged, so ask to remove it - # test "get_guidance_group_templates retuns all templates belonging to a guidance group" do - # GuidanceGroup.all.each do |group| - # group_templates = guidances(:related_policies).get_guidance_group_templates?(group) - # group.dmptemplates.each do |template| - # assert_includes(group_templates, template, "group #{group.name} should include template #{template.title}") - # end - # end - # end - -end - - - - - - - - diff --git a/test/unit/organisation_type_test.rb b/test/unit/organisation_type_test.rb deleted file mode 100644 index 31cccdc..0000000 --- a/test/unit/organisation_type_test.rb +++ /dev/null @@ -1,49 +0,0 @@ -require 'test_helper' - -class OrganisationTypeTest < ActiveSupport::TestCase - def setup - # OrganisationTypes MUST match those defined in the locale's magic strings file - @organisation_type = organisation_types(I18n.t("magic_strings.organisation_types").first[0]) - end - - # --------------------------------------------------- - test "required fields are required" do - assert_not OrganisationType.new.valid? - assert_not OrganisationType.new(description: 'testing').valid? - - assert OrganisationType.new(name: 'test').valid? - assert OrganisationType.new(name: 'test', description: 'testing').valid? - end - - # --------------------------------------------------- - test "name must be unique" do - assert_not OrganisationType.new(name: @organisation_type.name).valid? - end - - # --------------------------------------------------- - test "can manage has_many relationship with Organisations" do - organisation = Organisation.new(name: 'test') - verify_has_many_relationship(@organisation_type, organisation, - @organisation_type.organisations.count) - end - - # --------------------------------------------------- - test "can CRUD" do - ot = OrganisationType.create(name: 'test', description: 'testing') - assert_not ot.id.nil?, "was expecting to be able to create a new OrganisationType" - - ot.description = 'testing 2' - ot.save! - ot.reload - assert_equal 'testing 2', ot.description, "Was expecting to be able to update the description of the OrganisationType!" - - assert ot.destroy!, "Was unable to delete the OrganisationType!" - end - - # --------------------------------------------------- - test "magic strings match the values in the database/fixtures" do - I18n.t("magic_strings.organisation_types").each do |k,v| - assert_not OrganisationType.find_by(name: v).nil?, "An OrganisationType called #{v} is defined in the magic strings section of the locale file, but no matching value exists in the datbase/fixtures!" - end - end -end \ No newline at end of file diff --git a/test/unit/page_test.rb b/test/unit/page_test.rb deleted file mode 100644 index ff943a7..0000000 --- a/test/unit/page_test.rb +++ /dev/null @@ -1,7 +0,0 @@ -require 'test_helper' - -class PageTest < ActiveSupport::TestCase - # test "the truth" do - # assert true - # end -end diff --git a/test/unit/phase_test.rb b/test/unit/phase_test.rb deleted file mode 100644 index 65ecf3d..0000000 --- a/test/unit/phase_test.rb +++ /dev/null @@ -1,7 +0,0 @@ -require 'test_helper' - -class PhaseTest < ActiveSupport::TestCase - # test "the truth" do - # assert true - # end -end diff --git a/test/unit/plan_section_test.rb b/test/unit/plan_section_test.rb deleted file mode 100644 index 68788db..0000000 --- a/test/unit/plan_section_test.rb +++ /dev/null @@ -1,7 +0,0 @@ -require 'test_helper' - -class PlanSectionTest < ActiveSupport::TestCase - # test "the truth" do - # assert true - # end -end diff --git a/test/unit/plan_test.rb b/test/unit/plan_test.rb deleted file mode 100644 index 2cbd092..0000000 --- a/test/unit/plan_test.rb +++ /dev/null @@ -1,87 +0,0 @@ -require 'test_helper' - -class PlanTest < ActiveSupport::TestCase -=begin - def setup - @plan = Plan.new.tap do |p| - p.project = Project.new - end - end - - def settings(extras = {}) - { - margin: (@margin || { top: 10, bottom: 10, left: 10, right: 10 }), - font_face: (@font_face || Settings::Dmptemplate::VALID_FONT_FACES.first), - font_size: (@font_size || 11) - }.merge(extras) - end - - # settings - - test "no explicit settings should be Settings::Dmptemplate::DEFAULT_SETTINGS" do - assert(!@plan.settings(:export).value?) - assert_equal(Settings::Dmptemplate::DEFAULT_SETTINGS[:formatting], @plan.settings(:export).formatting) - end - - test "no explicit settings with template settings should use template settings" do - template = dmptemplates(:ahrc_template) - template.settings(:export).update_attributes(formatting: settings) - - @plan.project.dmptemplate = template - - assert(!@plan.super_settings(:export).value?) - assert(template.settings(:export).value?) - - assert_equal(settings, template.settings(:export).formatting) - assert_equal(settings, @plan.settings(:export).formatting) - end - - test "explicit settings with template settings should use plan settings" do - template_settings = settings - plan_settings = settings(font_size: 14) - - template = dmptemplates(:ahrc_template) - template.settings(:export).update_attributes(formatting: template_settings) - - @plan.project.dmptemplate = template - @plan.super_settings(:export).formatting = plan_settings - @plan.save! - @plan.reload - - assert(@plan.super_settings(:export).value?) - assert(@plan.settings(:export).value?) - assert(template.settings(:export).value?) - - assert_not_equal(plan_settings, template_settings) - assert_equal(template_settings, template.settings(:export).formatting) - assert_equal(plan_settings, @plan.settings(:export).formatting) - end - - test "explicit settings should not affect other plans with same template" do - template_settings = settings - plan_settings = settings(font_size: 14) - - template = dmptemplates(:ahrc_template) - template.settings(:export).update_attributes(formatting: template_settings) - - @plan.project.dmptemplate = template - @plan.super_settings(:export).formatting = plan_settings - @plan.save! - @plan.reload - - other_plan = Plan.new.tap do |plan| - plan.project = Project.new.tap {|p| p.dmptemplate = template } - end - - other_plan.save! - other_plan.reload - - assert(@plan.super_settings(:export).value?) - assert(@plan.settings(:export).value?) - assert(template.settings(:export).value?) - - assert_not_equal(plan_settings, other_plan.settings(:export).formatting) - assert_equal(template_settings, other_plan.settings(:export).formatting) - end -=end -end diff --git a/test/unit/project_group_test.rb b/test/unit/project_group_test.rb deleted file mode 100644 index 891b697..0000000 --- a/test/unit/project_group_test.rb +++ /dev/null @@ -1,7 +0,0 @@ -require 'test_helper' - -class ProjectGroupTest < ActiveSupport::TestCase - # test "the truth" do - # assert true - # end -end diff --git a/test/unit/project_partner_test.rb b/test/unit/project_partner_test.rb deleted file mode 100644 index 7324b6c..0000000 --- a/test/unit/project_partner_test.rb +++ /dev/null @@ -1,7 +0,0 @@ -require 'test_helper' - -class ProjectPartnerTest < ActiveSupport::TestCase - # test "the truth" do - # assert true - # end -end diff --git a/test/unit/project_test.rb b/test/unit/project_test.rb deleted file mode 100644 index 72cbb5c..0000000 --- a/test/unit/project_test.rb +++ /dev/null @@ -1,21 +0,0 @@ -require 'test_helper' - -class ProjectTest < ActiveSupport::TestCase - # test "the truth" do - # assert true - # end - - setup do - @project = Project.new({ - title: 'My Test Project', - dmptemplate: Dmptemplate.first, - organisation: Organisation.first - }) - end - - # --------------------------------------------------- - test "can manage belongs_to relationship with Visibility" do - verify_belongs_to_relationship(@project, Visibility.first) - end - -end diff --git a/test/unit/question_test.rb b/test/unit/question_test.rb deleted file mode 100644 index f54eeaa..0000000 --- a/test/unit/question_test.rb +++ /dev/null @@ -1,7 +0,0 @@ -require 'test_helper' - -class QuestionTest < ActiveSupport::TestCase - # test "the truth" do - # assert true - # end -end diff --git a/test/unit/section_test.rb b/test/unit/section_test.rb deleted file mode 100644 index f21fdcf..0000000 --- a/test/unit/section_test.rb +++ /dev/null @@ -1,7 +0,0 @@ -require 'test_helper' - -class SectionTest < ActiveSupport::TestCase - # test "the truth" do - # assert true - # end -end diff --git a/test/unit/theme_test.rb b/test/unit/theme_test.rb deleted file mode 100644 index c61fe99..0000000 --- a/test/unit/theme_test.rb +++ /dev/null @@ -1,7 +0,0 @@ -require 'test_helper' - -class ThemeTest < ActiveSupport::TestCase - # test "the truth" do - # assert true - # end -end diff --git a/test/unit/user_role_type_test.rb b/test/unit/user_role_type_test.rb deleted file mode 100644 index eca639c..0000000 --- a/test/unit/user_role_type_test.rb +++ /dev/null @@ -1,7 +0,0 @@ -require 'test_helper' - -class UserRoleTypeTest < ActiveSupport::TestCase - # test "the truth" do - # assert true - # end -end diff --git a/test/unit/user_test.rb b/test/unit/user_test.rb index fe4a712..194cd8b 100644 --- a/test/unit/user_test.rb +++ b/test/unit/user_test.rb @@ -188,7 +188,7 @@ project = Project.new(title: 'Test Project', dmptemplate_id: @dmptemplate.id) plan = Plan.new(project: project) question = Question.new(text: 'testing question') - answer = Answer.new(plan: plan, question: question) + answer = Answer.new(plan: plan, question: question, text: "Here's my answer") verify_has_many_relationship(@super, answer, @super.answers.count) end diff --git a/test/unit/version_test.rb b/test/unit/version_test.rb deleted file mode 100644 index a1a033c..0000000 --- a/test/unit/version_test.rb +++ /dev/null @@ -1,7 +0,0 @@ -require 'test_helper' - -class VersionTest < ActiveSupport::TestCase - # test "the truth" do - # assert true - # end -end