From 4108a9f6c8a34e8ecdd782c1fbb96d5a33572a9f Mon Sep 17 00:00:00 2001 From: Ben Topping Date: Mon, 19 Aug 2024 13:54:07 +0100 Subject: [PATCH 1/9] feat(tag-sets): adds index and show pages for tag sets --- .../tag_layout_templates_controller.rb | 3 +- app/controllers/tag_sets_controller.rb | 48 +++++++++++++++++++ app/models/ability/base_user.rb | 1 + .../ability/shared/tag_creation_user.rb | 3 +- app/resources/api/v2/tag_set_resource.rb | 29 +++++++++++ app/views/tag_layout_templates/new.html.erb | 2 +- app/views/tag_sets/index.html.erb | 21 ++++++++ app/views/tag_sets/show.html.erb | 17 +++++++ config/routes.rb | 2 + .../resources/api/v2/tag_set_resource_spec.rb | 20 ++++++++ 10 files changed, 143 insertions(+), 3 deletions(-) create mode 100644 app/controllers/tag_sets_controller.rb create mode 100644 app/resources/api/v2/tag_set_resource.rb create mode 100644 app/views/tag_sets/index.html.erb create mode 100644 app/views/tag_sets/show.html.erb create mode 100644 spec/resources/api/v2/tag_set_resource_spec.rb diff --git a/app/controllers/tag_layout_templates_controller.rb b/app/controllers/tag_layout_templates_controller.rb index 94c623b80c..cac8db6907 100644 --- a/app/controllers/tag_layout_templates_controller.rb +++ b/app/controllers/tag_layout_templates_controller.rb @@ -23,7 +23,8 @@ def show ## # Allows for the passing in of tag group id using a link from the tag group show page. def new - @tag_layout_template = TagLayoutTemplate.new(tag_group_id: params[:tag_group_id]) + @tag_layout_template = + TagLayoutTemplate.new(tag_group_id: params[:tag_group_id], tag2_group_id: params[:tag2_group_id]) @direction_algorithms = TagLayout::DIRECTION_ALGORITHMS @walking_algorithms = TagLayout::WALKING_ALGORITHMS diff --git a/app/controllers/tag_sets_controller.rb b/app/controllers/tag_sets_controller.rb new file mode 100644 index 0000000000..a68900e80e --- /dev/null +++ b/app/controllers/tag_sets_controller.rb @@ -0,0 +1,48 @@ +# frozen_string_literal: true +## +# This class is the controller for Tag Sets which are used to link together two related tag groups. +# It allows you to create and view Tag Sets. +class TagSetsController < ApplicationController + authorize_resource + + def index + @tag_sets = TagSet.all + + respond_to { |format| format.html } + end + + def show + @tag_set = TagSet.find(params[:id]) + + respond_to { |format| format.html } + end + + # ## + # # The new method uses a form object to handle the naming of the Tag Group and the input + # # and validation of the Tag oligo sequences. + # def new + # @form_object = TagGroup::FormObject.new + + # respond_to { |format| format.html } + # end + + # ## + # # The create method uses a form object to validate the user input of the oligo sequences + # # and handle the creation of Tags within a new Tag Group. + # def create + # @form_object = TagGroup::FormObject.new(tag_group_form_object_params) + + # respond_to do |format| + # if @form_object.save + # flash[:notice] = 'Tag Group was successfully created.' + # format.html { redirect_to(@form_object.tag_group) } + # else + # format.html { render action: 'new' } + # end + # end + # end + + # def tag_group_form_object_params + # params.require(:tag_group).permit(:name, :oligos_text, :adapter_type_id) + # end +end diff --git a/app/models/ability/base_user.rb b/app/models/ability/base_user.rb index 7c3983ba4a..1b2099ba7b 100644 --- a/app/models/ability/base_user.rb +++ b/app/models/ability/base_user.rb @@ -34,6 +34,7 @@ def grant_privileges # rubocop:todo Metrics/AbcSize, Metrics/MethodLength can :print_asset_group_labels, Study, managers: { id: user.id } can %i[read create update edit], Submission can :read, [TagGroup, TagLayoutTemplate] + can :read, TagSet can %i[read update print_swipecard], User, { id: user.id } can %i[projects study_reports], User diff --git a/app/models/ability/shared/tag_creation_user.rb b/app/models/ability/shared/tag_creation_user.rb index 11c2fe8d18..79a629513e 100644 --- a/app/models/ability/shared/tag_creation_user.rb +++ b/app/models/ability/shared/tag_creation_user.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true # Prepend to an ability class to include Tag Creation User privileges -# Govern the ability to created tag groups and layouts +# Govern the ability to create tag groups, layouts and sets module Ability::Shared::TagCreationUser def grant_privileges super @@ -11,5 +11,6 @@ def grant_privileges Rails.logger.debug { 'Granting TagCreationUser privileges' } can :manage, TagGroup can :manage, TagLayoutTemplate + can :manage, TagSet end end diff --git a/app/resources/api/v2/tag_set_resource.rb b/app/resources/api/v2/tag_set_resource.rb new file mode 100644 index 0000000000..d950bd6310 --- /dev/null +++ b/app/resources/api/v2/tag_set_resource.rb @@ -0,0 +1,29 @@ +# frozen_string_literal: true + +module Api + module V2 + # @todo This documentation does not yet include a detailed description of what this resource represents. + # @todo This documentation does not yet include detailed descriptions for relationships, attributes and filters. + # @todo This documentation does not yet include any example usage of the API via cURL or similar. + # + # @note Access this resource via the `/api/v2/tag_sets/` endpoint. + # + # Provides a JSON:API representation of {TagGroup}. + # + # For more information about JSON:API see the [JSON:API Specifications](https://jsonapi.org/format/) + # or look at the [JSONAPI::Resources](http://jsonapi-resources.com/) package for Sequencescape's implementation + # of the JSON:API standard. + class TagSetResource < BaseResource + # Associations + has_one :tag_group + has_one :tag2_group, class_name: 'TagGroup' + + # Attributes + attribute :name, readonly: true + + # Filters + filter :visible, default: true + filter :name + end + end +end diff --git a/app/views/tag_layout_templates/new.html.erb b/app/views/tag_layout_templates/new.html.erb index 9fed6ffeb8..ad52749aa4 100644 --- a/app/views/tag_layout_templates/new.html.erb +++ b/app/views/tag_layout_templates/new.html.erb @@ -15,7 +15,7 @@
<%= f.label :tag2_group, 'Tag2 Group' %>
- <%= f.select :tag2_group_id, TagGroup.visible.pluck(:name, :id), { prompt: 'Select tag2 group...' }, { class: 'form-control select2' } %> + <%= f.select :tag2_group_id, TagGroup.visible.pluck(:name, :id), { prompt: 'Select tag2 group...', selected: @tag_layout_template.tag2_group_id }, { class: 'form-control select2' } %>
diff --git a/app/views/tag_sets/index.html.erb b/app/views/tag_sets/index.html.erb new file mode 100644 index 0000000000..572127d112 --- /dev/null +++ b/app/views/tag_sets/index.html.erb @@ -0,0 +1,21 @@ + + + + + + + + + + + + <% for tag_set in @tag_sets %> + + + + + + + <% end %> + +
NameTag group (i7)Tag group (i5)
<%= tag_set.name %><%= tag_set.tag_group.name %><%= tag_set.tag2_group&.name %><%= link_to 'Show', tag_set %>
diff --git a/app/views/tag_sets/show.html.erb b/app/views/tag_sets/show.html.erb new file mode 100644 index 0000000000..e0fa3dec7a --- /dev/null +++ b/app/views/tag_sets/show.html.erb @@ -0,0 +1,17 @@ + +<% add :menu, "All Tag Sets" => tag_sets_path(@asset) %> + +<%= page_title('Tag Set', @tag_set.name) %> + +
+
Name
<%= @tag_set.name %>
+
Tag group (i7)
<%= @tag_set.tag_group.name %>
+
Tag group (i5)
<%= @tag_set.tag2_group&.name %>
+
+ +
+<% if can? :create, TagLayoutTemplate %> + <%= link_to 'Create a new tag layout template from this tag set', new_tag_layout_template_path(tag_group_id: @tag_set.tag_group.id, tag2_group_id: @tag_set.tag2_group&.id) %> +
+<% end %> +<%= link_to 'Back to tag sets list', tag_sets_path %> diff --git a/config/routes.rb b/config/routes.rb index 41d0b2485f..ebe4b045f3 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -451,6 +451,8 @@ resources :tags, except: %i[destroy index create new edit] end + resources :tag_sets, only: %i[index new create show] + resources :tag_layout_templates, only: %i[index new create show] resources :assets, except: %i[create new] do diff --git a/spec/resources/api/v2/tag_set_resource_spec.rb b/spec/resources/api/v2/tag_set_resource_spec.rb new file mode 100644 index 0000000000..c6abcea00c --- /dev/null +++ b/spec/resources/api/v2/tag_set_resource_spec.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +require 'rails_helper' +require './app/resources/api/v2/tag_set_resource' + +RSpec.describe Api::V2::TagSetResource, type: :resource do + subject { described_class.new(resource_model, {}) } + + let(:resource_model) { build_stubbed :tag_set } + + it 'exposes attributes', :aggregate_failures do + expect(subject).to have_attribute :name + expect(subject).not_to have_updatable_field(:name) + end + + it 'exposes associations', :aggregate_failures do + expect(subject).to have_one(:tag_group).with_class_name('TagGroup') + expect(subject).to have_one(:tag2_group).with_class_name('TagGroup') + end +end From 838a5dafe132b77797289303c799f10ecab79f54 Mon Sep 17 00:00:00 2001 From: Ben Topping Date: Mon, 19 Aug 2024 14:24:16 +0100 Subject: [PATCH 2/9] feat(tag-sets): adds tag set creation page --- app/controllers/tag_sets_controller.rb | 55 +++++++++---------- .../api/v2/tag_layout_template_resource.rb | 1 - app/views/tag_sets/index.html.erb | 5 ++ app/views/tag_sets/new.html.erb | 26 +++++++++ .../resources/api/v2/tag_set_resource_spec.rb | 10 ++-- 5 files changed, 63 insertions(+), 34 deletions(-) create mode 100644 app/views/tag_sets/new.html.erb diff --git a/app/controllers/tag_sets_controller.rb b/app/controllers/tag_sets_controller.rb index a68900e80e..87ca80b921 100644 --- a/app/controllers/tag_sets_controller.rb +++ b/app/controllers/tag_sets_controller.rb @@ -17,32 +17,31 @@ def show respond_to { |format| format.html } end - # ## - # # The new method uses a form object to handle the naming of the Tag Group and the input - # # and validation of the Tag oligo sequences. - # def new - # @form_object = TagGroup::FormObject.new - - # respond_to { |format| format.html } - # end - - # ## - # # The create method uses a form object to validate the user input of the oligo sequences - # # and handle the creation of Tags within a new Tag Group. - # def create - # @form_object = TagGroup::FormObject.new(tag_group_form_object_params) - - # respond_to do |format| - # if @form_object.save - # flash[:notice] = 'Tag Group was successfully created.' - # format.html { redirect_to(@form_object.tag_group) } - # else - # format.html { render action: 'new' } - # end - # end - # end - - # def tag_group_form_object_params - # params.require(:tag_group).permit(:name, :oligos_text, :adapter_type_id) - # end + def new + @tag_set = TagSet.new + + respond_to { |format| format.html } + end + + def create # rubocop:todo Metrics/MethodLength + @tag_set = TagSet.new(tag_set_params) + + respond_to do |format| + if @tag_set.save + flash[:notice] = 'Tag Set successfully created' + format.html { redirect_to tag_set_path(@tag_set) } + format.xml { render xml: @tag_set, status: :created, location: @tag_set } + format.json { render json: @tag_set, status: :created, location: @tag_set } + else + flash[:error] = 'Problems creating your new Tag Set' + format.html { render action: :new } + format.xml { render xml: @tag_set.errors, status: :unprocessable_entity } + format.json { render json: @tag_set.errors, status: :unprocessable_entity } + end + end + end + + def tag_set_params + params.require(:tag_set).permit(:name, :tag_group_id, :tag2_group_id) + end end diff --git a/app/resources/api/v2/tag_layout_template_resource.rb b/app/resources/api/v2/tag_layout_template_resource.rb index 4dd63a48a2..fc5c8c7abb 100644 --- a/app/resources/api/v2/tag_layout_template_resource.rb +++ b/app/resources/api/v2/tag_layout_template_resource.rb @@ -23,7 +23,6 @@ class TagLayoutTemplateResource < BaseResource # A relationship for the primary tag group associated with the tag layout template. # @return [Api::V2::TagGroupResource] has_one :tag_group - has_one :tag2_group # @!attribute [r] tag2_group # A relationship for the secondary tag group associated with the tag layout template. diff --git a/app/views/tag_sets/index.html.erb b/app/views/tag_sets/index.html.erb index 572127d112..0cc7abcfe6 100644 --- a/app/views/tag_sets/index.html.erb +++ b/app/views/tag_sets/index.html.erb @@ -19,3 +19,8 @@ <% end %> + + +<% if can? :create, TagSet %> + <%= link_to 'Create a new Tag Set', new_tag_set_path %> +<% end %> diff --git a/app/views/tag_sets/new.html.erb b/app/views/tag_sets/new.html.erb new file mode 100644 index 0000000000..f117ab2cdb --- /dev/null +++ b/app/views/tag_sets/new.html.erb @@ -0,0 +1,26 @@ + + + +<%= form_for(@tag_set) do |f| %> + <%= render_error_messages(@tag_set) %> +
+ <%= f.label :name, 'Tag Set name' %>
+ <%= f.text_field :name, class: 'form-control' %> +
+ +
+ <%= f.label :tag_group_id, 'Tag Group (i7)' %>
+ <%= f.select(:tag_group_id, TagGroup.pluck(:name, :id), { prompt: 'Unspecified' }, class: 'form-control select2' )%> +
+ +
+ <%= f.label :tag2_group_id, 'Tag Group (i5)' %>
+ <%= f.select(:tag2_group_id, TagGroup.pluck(:name, :id), { prompt: 'Unspecified' }, class: 'form-control select2' )%> +
+ +
+ <%= f.submit('Create tag set', class: 'btn btn-success') %> +
+<% end %> + +<%= link_to 'Back to tag sets list', tag_sets_path %> diff --git a/spec/resources/api/v2/tag_set_resource_spec.rb b/spec/resources/api/v2/tag_set_resource_spec.rb index c6abcea00c..80322d3404 100644 --- a/spec/resources/api/v2/tag_set_resource_spec.rb +++ b/spec/resources/api/v2/tag_set_resource_spec.rb @@ -4,17 +4,17 @@ require './app/resources/api/v2/tag_set_resource' RSpec.describe Api::V2::TagSetResource, type: :resource do - subject { described_class.new(resource_model, {}) } + subject(:tag_set) { described_class.new(resource_model, {}) } let(:resource_model) { build_stubbed :tag_set } it 'exposes attributes', :aggregate_failures do - expect(subject).to have_attribute :name - expect(subject).not_to have_updatable_field(:name) + expect(tag_set).to have_attribute :name + expect(tag_set).not_to have_updatable_field(:name) end it 'exposes associations', :aggregate_failures do - expect(subject).to have_one(:tag_group).with_class_name('TagGroup') - expect(subject).to have_one(:tag2_group).with_class_name('TagGroup') + expect(tag_set).to have_one(:tag_group).with_class_name('TagGroup') + expect(tag_set).to have_one(:tag2_group).with_class_name('TagGroup') end end From 7cdf673cabd08ecabb2b527718013fd4e6e3f8d5 Mon Sep 17 00:00:00 2001 From: Ben Topping Date: Mon, 19 Aug 2024 15:28:06 +0100 Subject: [PATCH 3/9] tests(tag-sets): adds various tag sets tests --- app/controllers/tag_sets_controller.rb | 9 +--- spec/controllers/tag_sets_controller_spec.rb | 29 +++++++++++ spec/features/tag_layout_template_spec.rb | 22 ++++++++ spec/features/tag_set_spec.rb | 55 ++++++++++++++++++++ spec/models/ability_spec.rb | 3 ++ 5 files changed, 111 insertions(+), 7 deletions(-) create mode 100644 spec/controllers/tag_sets_controller_spec.rb create mode 100644 spec/features/tag_set_spec.rb diff --git a/app/controllers/tag_sets_controller.rb b/app/controllers/tag_sets_controller.rb index 87ca80b921..007bdfd918 100644 --- a/app/controllers/tag_sets_controller.rb +++ b/app/controllers/tag_sets_controller.rb @@ -23,20 +23,15 @@ def new respond_to { |format| format.html } end - def create # rubocop:todo Metrics/MethodLength + def create @tag_set = TagSet.new(tag_set_params) respond_to do |format| if @tag_set.save - flash[:notice] = 'Tag Set successfully created' + flash[:notice] = 'Tag Set was successfully created.' format.html { redirect_to tag_set_path(@tag_set) } - format.xml { render xml: @tag_set, status: :created, location: @tag_set } - format.json { render json: @tag_set, status: :created, location: @tag_set } else - flash[:error] = 'Problems creating your new Tag Set' format.html { render action: :new } - format.xml { render xml: @tag_set.errors, status: :unprocessable_entity } - format.json { render json: @tag_set.errors, status: :unprocessable_entity } end end end diff --git a/spec/controllers/tag_sets_controller_spec.rb b/spec/controllers/tag_sets_controller_spec.rb new file mode 100644 index 0000000000..3aebbccb17 --- /dev/null +++ b/spec/controllers/tag_sets_controller_spec.rb @@ -0,0 +1,29 @@ +# frozen_string_literal: true + +require 'rails_helper' + +RSpec.describe TagSetsController do + let(:current_user) { create :user } + + it_behaves_like 'it requires login' + + describe '#index' do + before { get :index, session: { user: current_user.id } } + + it 'is successful' do + expect(response).to have_http_status(:success) + expect(response).to render_template('index') + end + end + + describe '#show' do + let(:tag_set) { create :tag_set } + + before { get :show, params: { id: tag_set.id }, session: { user: current_user.id } } + + it 'is successful' do + expect(response).to have_http_status(:success) + expect(response).to render_template('show') + end + end +end diff --git a/spec/features/tag_layout_template_spec.rb b/spec/features/tag_layout_template_spec.rb index 1d9d8fc963..923ab8c783 100644 --- a/spec/features/tag_layout_template_spec.rb +++ b/spec/features/tag_layout_template_spec.rb @@ -6,10 +6,12 @@ let(:user) { create :admin } let(:tag_group_1) { create(:tag_group_with_tags, name: 'Test tag group 1') } let(:tag_group_2) { create(:tag_group_with_tags, name: 'Test tag group 2') } + let(:tag_set_1) { create(:tag_set, name: 'Test tag set 1') } before do tag_group_1 tag_group_2 + tag_set_1 end it 'create a new layout template from a tag group', :js do @@ -32,6 +34,26 @@ expect(page).to have_content 'To tag layout templates list' end + it 'create a new layout template from a tag set', :js do + login_user user + visit tag_set_path(tag_set_1) + expect(page).to have_content 'Test tag set 1' + click_on 'Create a new tag layout template from this tag set' + expect(page).to have_content 'Tag Layout Template New' + within('#new_tag_layout_template') do + fill_in('tag_layout_template_name', with: 'Test tag layout template') + select('column', from: 'tag_layout_template_direction_algorithm') + click_on 'Create tag layout template' + end + expect(page).to have_content 'The Tag Layout Template has been successfully created.' + expect(page).to have_content 'Name: Test tag layout template' + expect(page).to have_content "Tag Group: #{tag_set_1.tag_group.name}" + expect(page).to have_content "Tag2 Group: #{tag_set_1.tag2_group.name}" + expect(page).to have_content 'Direction the tags are laid out by: column' + expect(page).to have_content 'Walking by: wells of plate' + expect(page).to have_content 'To tag layout templates list' + end + it 'create a new layout template directly', :js do login_user user visit new_tag_layout_template_path diff --git a/spec/features/tag_set_spec.rb b/spec/features/tag_set_spec.rb new file mode 100644 index 0000000000..c210cf54de --- /dev/null +++ b/spec/features/tag_set_spec.rb @@ -0,0 +1,55 @@ +# frozen_string_literal: true + +require 'rails_helper' + +describe 'Create a new tag set' do + let(:user) { create :admin } + let(:adapter_type) { create :adapter_type } + let(:tag_group) { create :tag_group, name: 'test-group-1', adapter_type: adapter_type } + let(:tag2_group) { create :tag_group, name: 'test-group-2', adapter_type: adapter_type } + + before do + tag_group + tag2_group + end + + it 'view tag sets and create a new valid one' do + login_user user + visit tag_sets_path + expect(page).to have_content 'Listing Tag Sets' + click_on 'Create a new Tag Set' + expect(page).to have_content 'New Tag Set' + fill_in('tag_set_name', with: 'Test tag set') + select(tag_group.name, from: 'Tag Group (i7)') + select(tag2_group.name, from: 'Tag Group (i5)') + click_on 'Create tag set' + expect(page).to have_content 'Tag Set was successfully created.' + expect(page).to have_content 'Test tag set' + expect(page).to have_content tag_group.name + expect(page).to have_content tag2_group.name + expect(page).to have_content 'Create a new tag layout template from this tag set' + end + + it 'view tag groups and attempt to create a new one with an existing tag set name' do + create(:tag_set, name: 'Test tag set') + + login_user user + visit tag_sets_path + expect(page).to have_content 'Listing Tag Sets' + click_on 'Create a new Tag Set' + expect(page).to have_content 'New Tag Set' + fill_in('tag_set_name', with: 'Test tag set') + select(tag_group.name, from: 'Tag Group (i7)') + select(tag2_group.name, from: 'Tag Group (i5)') + click_on 'Create tag set' + expect(page).to have_content 'error prohibited this tag set from being saved' + expect(page).to have_content 'Name has already been taken' + fill_in('tag_set_name', with: 'Test tag set 1') + click_on 'Create tag set' + expect(page).to have_content 'Tag Set was successfully created.' + expect(page).to have_content 'Test tag set 1' + expect(page).to have_content tag_group.name + expect(page).to have_content tag2_group.name + expect(page).to have_content 'Create a new tag layout template from this tag set' + end +end diff --git a/spec/models/ability_spec.rb b/spec/models/ability_spec.rb index f0a69e9262..4a5863b2f7 100644 --- a/spec/models/ability_spec.rb +++ b/spec/models/ability_spec.rb @@ -73,6 +73,7 @@ Submission => %i[create read edit update delete change_priority new order_fields study_assets], Supplier => %i[create new], TagGroup => %i[create read edit delete], + TagSet => %i[create read edit delete], TagLayoutTemplate => %i[create read edit delete], User => %i[administer edit read projects study_reports create delete] } @@ -95,6 +96,7 @@ Study => %i[create read print_asset_group_labels], Submission => %i[create read update new order_fields study_assets edit], TagGroup => %i[read], + TagSet => %i[read], TagLayoutTemplate => %i[read], User => %i[edit read projects study_reports print_swipecard] } @@ -194,6 +196,7 @@ def merge_permissions(*permissions) Submission => %i[delete change_priority], Supplier => %i[create new], TagGroup => %i[create edit delete], + TagSet => %i[create edit delete], TagLayoutTemplate => %i[create edit delete], User => %i[administer create delete] } From 1fbbe5487d5d9f4d249630a6dbb6db09535e2aba Mon Sep 17 00:00:00 2001 From: Ben Topping Date: Mon, 19 Aug 2024 15:54:42 +0100 Subject: [PATCH 4/9] style(tag-sets): adds links to tag_groups on tag sets show page --- app/views/tag_sets/show.html.erb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/tag_sets/show.html.erb b/app/views/tag_sets/show.html.erb index e0fa3dec7a..10682dda1d 100644 --- a/app/views/tag_sets/show.html.erb +++ b/app/views/tag_sets/show.html.erb @@ -5,8 +5,8 @@
Name
<%= @tag_set.name %>
-
Tag group (i7)
<%= @tag_set.tag_group.name %>
-
Tag group (i5)
<%= @tag_set.tag2_group&.name %>
+
Tag group (i7)
<%= link_to @tag_set.tag_group.name, @tag_set.tag_group %>
+
Tag group (i5)
<%= @tag_set.tag2_group ? (link_to @tag_set.tag2_group&.name, @tag_set.tag2_group) : 'None'%>

From 27e2f212546acfba30d9453f6f243dd1795bc35c Mon Sep 17 00:00:00 2001 From: Ben Topping Date: Tue, 20 Aug 2024 14:44:22 +0100 Subject: [PATCH 5/9] feat(tag-sets): moves tag set pages to admin panel --- .../{ => admin}/tag_sets_controller.rb | 4 +- app/models/ability/base_user.rb | 1 - app/views/admin/index.html.erb | 7 ++ app/views/{ => admin}/tag_sets/index.html.erb | 4 +- app/views/{ => admin}/tag_sets/new.html.erb | 4 +- app/views/{ => admin}/tag_sets/show.html.erb | 4 +- config/routes.rb | 3 +- .../admin/tag_sets_controller_spec.rb | 67 +++++++++++++++++++ spec/controllers/tag_sets_controller_spec.rb | 29 -------- spec/features/{ => admin}/tag_set_spec.rb | 4 +- spec/models/ability_spec.rb | 1 - 11 files changed, 85 insertions(+), 43 deletions(-) rename app/controllers/{ => admin}/tag_sets_controller.rb (87%) rename app/views/{ => admin}/tag_sets/index.html.erb (77%) rename app/views/{ => admin}/tag_sets/new.html.erb (86%) rename app/views/{ => admin}/tag_sets/show.html.erb (82%) create mode 100644 spec/controllers/admin/tag_sets_controller_spec.rb delete mode 100644 spec/controllers/tag_sets_controller_spec.rb rename spec/features/{ => admin}/tag_set_spec.rb (97%) diff --git a/app/controllers/tag_sets_controller.rb b/app/controllers/admin/tag_sets_controller.rb similarity index 87% rename from app/controllers/tag_sets_controller.rb rename to app/controllers/admin/tag_sets_controller.rb index 007bdfd918..0b6a208d51 100644 --- a/app/controllers/tag_sets_controller.rb +++ b/app/controllers/admin/tag_sets_controller.rb @@ -2,7 +2,7 @@ ## # This class is the controller for Tag Sets which are used to link together two related tag groups. # It allows you to create and view Tag Sets. -class TagSetsController < ApplicationController +class Admin::TagSetsController < ApplicationController authorize_resource def index @@ -29,7 +29,7 @@ def create respond_to do |format| if @tag_set.save flash[:notice] = 'Tag Set was successfully created.' - format.html { redirect_to tag_set_path(@tag_set) } + format.html { redirect_to admin_tag_set_path(@tag_set) } else format.html { render action: :new } end diff --git a/app/models/ability/base_user.rb b/app/models/ability/base_user.rb index 1b2099ba7b..7c3983ba4a 100644 --- a/app/models/ability/base_user.rb +++ b/app/models/ability/base_user.rb @@ -34,7 +34,6 @@ def grant_privileges # rubocop:todo Metrics/AbcSize, Metrics/MethodLength can :print_asset_group_labels, Study, managers: { id: user.id } can %i[read create update edit], Submission can :read, [TagGroup, TagLayoutTemplate] - can :read, TagSet can %i[read update print_swipecard], User, { id: user.id } can %i[projects study_reports], User diff --git a/app/views/admin/index.html.erb b/app/views/admin/index.html.erb index 3d928de7d5..ccece3d1d9 100644 --- a/app/views/admin/index.html.erb +++ b/app/views/admin/index.html.erb @@ -107,4 +107,11 @@ Overview of granted abilities. <% end %> <% end %> + + <% if can? :manage, TagSet %> + <%= panel do %> +

<%= link_to "Tag set management", admin_tag_sets_path %>

+ Manage the tag sets. + <% end %> + <% end %>
diff --git a/app/views/tag_sets/index.html.erb b/app/views/admin/tag_sets/index.html.erb similarity index 77% rename from app/views/tag_sets/index.html.erb rename to app/views/admin/tag_sets/index.html.erb index 0cc7abcfe6..6f60a62ff8 100644 --- a/app/views/tag_sets/index.html.erb +++ b/app/views/admin/tag_sets/index.html.erb @@ -14,7 +14,7 @@ <%= tag_set.name %> <%= tag_set.tag_group.name %> <%= tag_set.tag2_group&.name %> - <%= link_to 'Show', tag_set %> + <%= link_to 'Show', admin_tag_set_path(tag_set.id) %> <% end %> @@ -22,5 +22,5 @@ <% if can? :create, TagSet %> - <%= link_to 'Create a new Tag Set', new_tag_set_path %> + <%= link_to 'Create a new Tag Set', new_admin_tag_set_path %> <% end %> diff --git a/app/views/tag_sets/new.html.erb b/app/views/admin/tag_sets/new.html.erb similarity index 86% rename from app/views/tag_sets/new.html.erb rename to app/views/admin/tag_sets/new.html.erb index f117ab2cdb..82c4ff8281 100644 --- a/app/views/tag_sets/new.html.erb +++ b/app/views/admin/tag_sets/new.html.erb @@ -1,7 +1,7 @@ -<%= form_for(@tag_set) do |f| %> +<%= form_for @tag_set, url: admin_tag_sets_path do |f| %> <%= render_error_messages(@tag_set) %>
<%= f.label :name, 'Tag Set name' %>
@@ -23,4 +23,4 @@
<% end %> -<%= link_to 'Back to tag sets list', tag_sets_path %> +<%= link_to 'Back to tag sets list', admin_tag_sets_path %> diff --git a/app/views/tag_sets/show.html.erb b/app/views/admin/tag_sets/show.html.erb similarity index 82% rename from app/views/tag_sets/show.html.erb rename to app/views/admin/tag_sets/show.html.erb index 10682dda1d..0b3ea0b5cb 100644 --- a/app/views/tag_sets/show.html.erb +++ b/app/views/admin/tag_sets/show.html.erb @@ -1,5 +1,5 @@ -<% add :menu, "All Tag Sets" => tag_sets_path(@asset) %> +<% add :menu, "All Tag Sets" => admin_tag_sets_path(@asset) %> <%= page_title('Tag Set', @tag_set.name) %> @@ -14,4 +14,4 @@ <%= link_to 'Create a new tag layout template from this tag set', new_tag_layout_template_path(tag_group_id: @tag_set.tag_group.id, tag2_group_id: @tag_set.tag2_group&.id) %>
<% end %> -<%= link_to 'Back to tag sets list', tag_sets_path %> +<%= link_to 'Back to tag sets list', admin_tag_sets_path %> diff --git a/config/routes.rb b/config/routes.rb index ebe4b045f3..b20b4cc1da 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -340,6 +340,7 @@ resources :faculty_sponsors resources :programs resources :delayed_jobs + resources :tag_sets, only: %i[index new create show] resources :users do collection { post :filter } @@ -451,8 +452,6 @@ resources :tags, except: %i[destroy index create new edit] end - resources :tag_sets, only: %i[index new create show] - resources :tag_layout_templates, only: %i[index new create show] resources :assets, except: %i[create new] do diff --git a/spec/controllers/admin/tag_sets_controller_spec.rb b/spec/controllers/admin/tag_sets_controller_spec.rb new file mode 100644 index 0000000000..793d7c29c0 --- /dev/null +++ b/spec/controllers/admin/tag_sets_controller_spec.rb @@ -0,0 +1,67 @@ +# frozen_string_literal: true + +require 'rails_helper' + +RSpec.describe Admin::TagSetsController do + let(:current_user) { create :user } + let(:tag_set) { create :tag_set } + + it_behaves_like 'it requires login' + + context 'when admin' do + before { session[:user] = create :admin } + + describe '#index' do + before { get :index } + + it 'is successful' do + expect(response).to have_http_status(:success) + expect(response).to render_template('index') + end + end + + describe '#show' do + let(:tag_set) { create :tag_set } + + before { get :show, params: { id: tag_set.id } } + + it 'is successful' do + expect(response).to have_http_status(:success) + expect(response).to render_template('show') + end + end + + describe '#create' do + before { post :create, params: { tag_set: { name: 'test-123', tag_group_id: create(:tag_group).id } } } + + it 'renders the show template' do + expect(response).to redirect_to admin_tag_set_path(TagSet.last) + end + end + end + + context 'when a non-admin' do + before { session[:user] = create :user } + + describe '#index' do + it 'redirects' do + get :index + expect(response).to redirect_to('/') + end + end + + describe '#new' do + it 'redirects' do + get :new + expect(response).to redirect_to('/') + end + end + + describe '#create' do + it 'redirects' do + post :create, params: attributes_for(:tag_set) + expect(response).to redirect_to('/') + end + end + end +end diff --git a/spec/controllers/tag_sets_controller_spec.rb b/spec/controllers/tag_sets_controller_spec.rb deleted file mode 100644 index 3aebbccb17..0000000000 --- a/spec/controllers/tag_sets_controller_spec.rb +++ /dev/null @@ -1,29 +0,0 @@ -# frozen_string_literal: true - -require 'rails_helper' - -RSpec.describe TagSetsController do - let(:current_user) { create :user } - - it_behaves_like 'it requires login' - - describe '#index' do - before { get :index, session: { user: current_user.id } } - - it 'is successful' do - expect(response).to have_http_status(:success) - expect(response).to render_template('index') - end - end - - describe '#show' do - let(:tag_set) { create :tag_set } - - before { get :show, params: { id: tag_set.id }, session: { user: current_user.id } } - - it 'is successful' do - expect(response).to have_http_status(:success) - expect(response).to render_template('show') - end - end -end diff --git a/spec/features/tag_set_spec.rb b/spec/features/admin/tag_set_spec.rb similarity index 97% rename from spec/features/tag_set_spec.rb rename to spec/features/admin/tag_set_spec.rb index c210cf54de..cdc23d0233 100644 --- a/spec/features/tag_set_spec.rb +++ b/spec/features/admin/tag_set_spec.rb @@ -15,7 +15,7 @@ it 'view tag sets and create a new valid one' do login_user user - visit tag_sets_path + visit admin_tag_sets_path expect(page).to have_content 'Listing Tag Sets' click_on 'Create a new Tag Set' expect(page).to have_content 'New Tag Set' @@ -34,7 +34,7 @@ create(:tag_set, name: 'Test tag set') login_user user - visit tag_sets_path + visit admin_tag_sets_path expect(page).to have_content 'Listing Tag Sets' click_on 'Create a new Tag Set' expect(page).to have_content 'New Tag Set' diff --git a/spec/models/ability_spec.rb b/spec/models/ability_spec.rb index 4a5863b2f7..e241827255 100644 --- a/spec/models/ability_spec.rb +++ b/spec/models/ability_spec.rb @@ -96,7 +96,6 @@ Study => %i[create read print_asset_group_labels], Submission => %i[create read update new order_fields study_assets edit], TagGroup => %i[read], - TagSet => %i[read], TagLayoutTemplate => %i[read], User => %i[edit read projects study_reports print_swipecard] } From ac8bf4a4ee6c1c68b9d42e101515c60fd6728c33 Mon Sep 17 00:00:00 2001 From: Ben Topping Date: Tue, 20 Aug 2024 14:49:34 +0100 Subject: [PATCH 6/9] misc: removes visible default filter from tag set resource --- app/resources/api/v2/tag_set_resource.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/app/resources/api/v2/tag_set_resource.rb b/app/resources/api/v2/tag_set_resource.rb index d950bd6310..66e38861da 100644 --- a/app/resources/api/v2/tag_set_resource.rb +++ b/app/resources/api/v2/tag_set_resource.rb @@ -22,7 +22,6 @@ class TagSetResource < BaseResource attribute :name, readonly: true # Filters - filter :visible, default: true filter :name end end From 4fd725c39ec7b3951944d179add3fdb043e9a42c Mon Sep 17 00:00:00 2001 From: Ben Topping Date: Tue, 20 Aug 2024 15:07:36 +0100 Subject: [PATCH 7/9] tests: fixes tag-set related tag set tests --- spec/features/tag_layout_template_spec.rb | 2 +- spec/models/ability_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/features/tag_layout_template_spec.rb b/spec/features/tag_layout_template_spec.rb index 923ab8c783..a59c2a53c0 100644 --- a/spec/features/tag_layout_template_spec.rb +++ b/spec/features/tag_layout_template_spec.rb @@ -36,7 +36,7 @@ it 'create a new layout template from a tag set', :js do login_user user - visit tag_set_path(tag_set_1) + visit admin_tag_set_path(tag_set_1) expect(page).to have_content 'Test tag set 1' click_on 'Create a new tag layout template from this tag set' expect(page).to have_content 'Tag Layout Template New' diff --git a/spec/models/ability_spec.rb b/spec/models/ability_spec.rb index e241827255..46848c4edc 100644 --- a/spec/models/ability_spec.rb +++ b/spec/models/ability_spec.rb @@ -195,7 +195,7 @@ def merge_permissions(*permissions) Submission => %i[delete change_priority], Supplier => %i[create new], TagGroup => %i[create edit delete], - TagSet => %i[create edit delete], + TagSet => %i[create read edit delete], TagLayoutTemplate => %i[create edit delete], User => %i[administer create delete] } From 1c7476f255480cbd9acf08053581251bc642f1be Mon Sep 17 00:00:00 2001 From: Ben Topping Date: Thu, 22 Aug 2024 14:15:57 +0100 Subject: [PATCH 8/9] feat(tag-sets): removes tag set resource, adds further controller tests --- app/resources/api/v2/tag_set_resource.rb | 28 ------------------ .../admin/tag_sets_controller_spec.rb | 29 +++++++++++++++++-- .../resources/api/v2/tag_set_resource_spec.rb | 20 ------------- 3 files changed, 26 insertions(+), 51 deletions(-) delete mode 100644 app/resources/api/v2/tag_set_resource.rb delete mode 100644 spec/resources/api/v2/tag_set_resource_spec.rb diff --git a/app/resources/api/v2/tag_set_resource.rb b/app/resources/api/v2/tag_set_resource.rb deleted file mode 100644 index 66e38861da..0000000000 --- a/app/resources/api/v2/tag_set_resource.rb +++ /dev/null @@ -1,28 +0,0 @@ -# frozen_string_literal: true - -module Api - module V2 - # @todo This documentation does not yet include a detailed description of what this resource represents. - # @todo This documentation does not yet include detailed descriptions for relationships, attributes and filters. - # @todo This documentation does not yet include any example usage of the API via cURL or similar. - # - # @note Access this resource via the `/api/v2/tag_sets/` endpoint. - # - # Provides a JSON:API representation of {TagGroup}. - # - # For more information about JSON:API see the [JSON:API Specifications](https://jsonapi.org/format/) - # or look at the [JSONAPI::Resources](http://jsonapi-resources.com/) package for Sequencescape's implementation - # of the JSON:API standard. - class TagSetResource < BaseResource - # Associations - has_one :tag_group - has_one :tag2_group, class_name: 'TagGroup' - - # Attributes - attribute :name, readonly: true - - # Filters - filter :name - end - end -end diff --git a/spec/controllers/admin/tag_sets_controller_spec.rb b/spec/controllers/admin/tag_sets_controller_spec.rb index 793d7c29c0..afe1386d97 100644 --- a/spec/controllers/admin/tag_sets_controller_spec.rb +++ b/spec/controllers/admin/tag_sets_controller_spec.rb @@ -31,12 +31,27 @@ end end - describe '#create' do - before { post :create, params: { tag_set: { name: 'test-123', tag_group_id: create(:tag_group).id } } } + describe '#new' do + before { get :new } - it 'renders the show template' do + it 'is successful' do + expect(response).to have_http_status(:success) + expect(response).to render_template('new') + end + end + + describe '#create' do + it 'redirects to the tag set show path' do + post :create, params: { tag_set: { name: 'test-123', tag_group_id: create(:tag_group).id } } expect(response).to redirect_to admin_tag_set_path(TagSet.last) end + + it 'renders the new template when there are errors' do + post :create, params: { tag_set: { name: 'test-123', tag_group_id: 'bad ID' } } + # Successful status because we handle and display the errors and remain on the new page + expect(response).to have_http_status(:success) + expect(response).to render_template('new') + end end end @@ -57,6 +72,14 @@ end end + describe '#show' do + it 'redirects' do + tag_set = create(:tag_set) + get :show, params: { id: tag_set.id } + expect(response).to redirect_to('/') + end + end + describe '#create' do it 'redirects' do post :create, params: attributes_for(:tag_set) diff --git a/spec/resources/api/v2/tag_set_resource_spec.rb b/spec/resources/api/v2/tag_set_resource_spec.rb deleted file mode 100644 index 80322d3404..0000000000 --- a/spec/resources/api/v2/tag_set_resource_spec.rb +++ /dev/null @@ -1,20 +0,0 @@ -# frozen_string_literal: true - -require 'rails_helper' -require './app/resources/api/v2/tag_set_resource' - -RSpec.describe Api::V2::TagSetResource, type: :resource do - subject(:tag_set) { described_class.new(resource_model, {}) } - - let(:resource_model) { build_stubbed :tag_set } - - it 'exposes attributes', :aggregate_failures do - expect(tag_set).to have_attribute :name - expect(tag_set).not_to have_updatable_field(:name) - end - - it 'exposes associations', :aggregate_failures do - expect(tag_set).to have_one(:tag_group).with_class_name('TagGroup') - expect(tag_set).to have_one(:tag2_group).with_class_name('TagGroup') - end -end From 7057ef4fcc0f114b2561d213934d8394fc02b420 Mon Sep 17 00:00:00 2001 From: Ben Topping Date: Wed, 28 Aug 2024 11:36:08 +0100 Subject: [PATCH 9/9] feat(tag-sets): returns tag_sets to non-admin setup and adds link to home page --- app/controllers/{admin => }/tag_sets_controller.rb | 4 ++-- app/models/ability/base_user.rb | 2 +- app/views/admin/index.html.erb | 7 ------- app/views/homes/show.html.erb | 1 + app/views/{admin => }/tag_sets/index.html.erb | 4 ++-- app/views/{admin => }/tag_sets/new.html.erb | 4 ++-- app/views/{admin => }/tag_sets/show.html.erb | 4 ++-- config/routes.rb | 3 ++- .../{admin => }/tag_sets_controller_spec.rb | 10 ++++++---- spec/features/tag_layout_template_spec.rb | 2 +- spec/features/{admin => }/tag_set_spec.rb | 4 ++-- spec/models/ability_spec.rb | 1 + 12 files changed, 22 insertions(+), 24 deletions(-) rename app/controllers/{admin => }/tag_sets_controller.rb (87%) rename app/views/{admin => }/tag_sets/index.html.erb (77%) rename app/views/{admin => }/tag_sets/new.html.erb (86%) rename app/views/{admin => }/tag_sets/show.html.erb (82%) rename spec/controllers/{admin => }/tag_sets_controller_spec.rb (86%) rename spec/features/{admin => }/tag_set_spec.rb (97%) diff --git a/app/controllers/admin/tag_sets_controller.rb b/app/controllers/tag_sets_controller.rb similarity index 87% rename from app/controllers/admin/tag_sets_controller.rb rename to app/controllers/tag_sets_controller.rb index 0b6a208d51..007bdfd918 100644 --- a/app/controllers/admin/tag_sets_controller.rb +++ b/app/controllers/tag_sets_controller.rb @@ -2,7 +2,7 @@ ## # This class is the controller for Tag Sets which are used to link together two related tag groups. # It allows you to create and view Tag Sets. -class Admin::TagSetsController < ApplicationController +class TagSetsController < ApplicationController authorize_resource def index @@ -29,7 +29,7 @@ def create respond_to do |format| if @tag_set.save flash[:notice] = 'Tag Set was successfully created.' - format.html { redirect_to admin_tag_set_path(@tag_set) } + format.html { redirect_to tag_set_path(@tag_set) } else format.html { render action: :new } end diff --git a/app/models/ability/base_user.rb b/app/models/ability/base_user.rb index 7c3983ba4a..5cec001764 100644 --- a/app/models/ability/base_user.rb +++ b/app/models/ability/base_user.rb @@ -33,7 +33,7 @@ def grant_privileges # rubocop:todo Metrics/AbcSize, Metrics/MethodLength can :print_asset_group_labels, Study, owners: { id: user.id } can :print_asset_group_labels, Study, managers: { id: user.id } can %i[read create update edit], Submission - can :read, [TagGroup, TagLayoutTemplate] + can :read, [TagGroup, TagLayoutTemplate, TagSet] can %i[read update print_swipecard], User, { id: user.id } can %i[projects study_reports], User diff --git a/app/views/admin/index.html.erb b/app/views/admin/index.html.erb index ccece3d1d9..3d928de7d5 100644 --- a/app/views/admin/index.html.erb +++ b/app/views/admin/index.html.erb @@ -107,11 +107,4 @@ Overview of granted abilities. <% end %> <% end %> - - <% if can? :manage, TagSet %> - <%= panel do %> -

<%= link_to "Tag set management", admin_tag_sets_path %>

- Manage the tag sets. - <% end %> - <% end %> diff --git a/app/views/homes/show.html.erb b/app/views/homes/show.html.erb index edc89bb947..899d6bea8f 100644 --- a/app/views/homes/show.html.erb +++ b/app/views/homes/show.html.erb @@ -17,6 +17,7 @@ <% add :menu, 'Plate Summaries' => plate_summaries_path %> <% add :menu, 'Create Custom Pools' => new_pooling_path %> <% add :menu, 'Status of Tube Rack Imports' => tube_rack_statuses_path %> +<% add :menu, 'Tag Sets' => tag_sets_path %> <% @links.each do |name, link| %> diff --git a/app/views/admin/tag_sets/index.html.erb b/app/views/tag_sets/index.html.erb similarity index 77% rename from app/views/admin/tag_sets/index.html.erb rename to app/views/tag_sets/index.html.erb index 6f60a62ff8..d99885fe2f 100644 --- a/app/views/admin/tag_sets/index.html.erb +++ b/app/views/tag_sets/index.html.erb @@ -14,7 +14,7 @@ <%= tag_set.name %> <%= tag_set.tag_group.name %> <%= tag_set.tag2_group&.name %> - <%= link_to 'Show', admin_tag_set_path(tag_set.id) %> + <%= link_to 'Show', tag_set_path(tag_set.id) %> <% end %> @@ -22,5 +22,5 @@ <% if can? :create, TagSet %> - <%= link_to 'Create a new Tag Set', new_admin_tag_set_path %> + <%= link_to 'Create a new Tag Set', new_tag_set_path %> <% end %> diff --git a/app/views/admin/tag_sets/new.html.erb b/app/views/tag_sets/new.html.erb similarity index 86% rename from app/views/admin/tag_sets/new.html.erb rename to app/views/tag_sets/new.html.erb index 82c4ff8281..9e26a57d3a 100644 --- a/app/views/admin/tag_sets/new.html.erb +++ b/app/views/tag_sets/new.html.erb @@ -1,7 +1,7 @@ -<%= form_for @tag_set, url: admin_tag_sets_path do |f| %> +<%= form_for @tag_set, url: tag_sets_path do |f| %> <%= render_error_messages(@tag_set) %>
<%= f.label :name, 'Tag Set name' %>
@@ -23,4 +23,4 @@
<% end %> -<%= link_to 'Back to tag sets list', admin_tag_sets_path %> +<%= link_to 'Back to tag sets list', tag_sets_path %> diff --git a/app/views/admin/tag_sets/show.html.erb b/app/views/tag_sets/show.html.erb similarity index 82% rename from app/views/admin/tag_sets/show.html.erb rename to app/views/tag_sets/show.html.erb index 0b3ea0b5cb..10682dda1d 100644 --- a/app/views/admin/tag_sets/show.html.erb +++ b/app/views/tag_sets/show.html.erb @@ -1,5 +1,5 @@ -<% add :menu, "All Tag Sets" => admin_tag_sets_path(@asset) %> +<% add :menu, "All Tag Sets" => tag_sets_path(@asset) %> <%= page_title('Tag Set', @tag_set.name) %> @@ -14,4 +14,4 @@ <%= link_to 'Create a new tag layout template from this tag set', new_tag_layout_template_path(tag_group_id: @tag_set.tag_group.id, tag2_group_id: @tag_set.tag2_group&.id) %>
<% end %> -<%= link_to 'Back to tag sets list', admin_tag_sets_path %> +<%= link_to 'Back to tag sets list', tag_sets_path %> diff --git a/config/routes.rb b/config/routes.rb index b20b4cc1da..ebe4b045f3 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -340,7 +340,6 @@ resources :faculty_sponsors resources :programs resources :delayed_jobs - resources :tag_sets, only: %i[index new create show] resources :users do collection { post :filter } @@ -452,6 +451,8 @@ resources :tags, except: %i[destroy index create new edit] end + resources :tag_sets, only: %i[index new create show] + resources :tag_layout_templates, only: %i[index new create show] resources :assets, except: %i[create new] do diff --git a/spec/controllers/admin/tag_sets_controller_spec.rb b/spec/controllers/tag_sets_controller_spec.rb similarity index 86% rename from spec/controllers/admin/tag_sets_controller_spec.rb rename to spec/controllers/tag_sets_controller_spec.rb index afe1386d97..9c9b934bf6 100644 --- a/spec/controllers/admin/tag_sets_controller_spec.rb +++ b/spec/controllers/tag_sets_controller_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' -RSpec.describe Admin::TagSetsController do +RSpec.describe TagSetsController do let(:current_user) { create :user } let(:tag_set) { create :tag_set } @@ -43,7 +43,7 @@ describe '#create' do it 'redirects to the tag set show path' do post :create, params: { tag_set: { name: 'test-123', tag_group_id: create(:tag_group).id } } - expect(response).to redirect_to admin_tag_set_path(TagSet.last) + expect(response).to redirect_to tag_set_path(TagSet.last) end it 'renders the new template when there are errors' do @@ -61,7 +61,8 @@ describe '#index' do it 'redirects' do get :index - expect(response).to redirect_to('/') + expect(response).to have_http_status(:success) + expect(response).to render_template('index') end end @@ -76,7 +77,8 @@ it 'redirects' do tag_set = create(:tag_set) get :show, params: { id: tag_set.id } - expect(response).to redirect_to('/') + expect(response).to have_http_status(:success) + expect(response).to render_template('show') end end diff --git a/spec/features/tag_layout_template_spec.rb b/spec/features/tag_layout_template_spec.rb index a59c2a53c0..923ab8c783 100644 --- a/spec/features/tag_layout_template_spec.rb +++ b/spec/features/tag_layout_template_spec.rb @@ -36,7 +36,7 @@ it 'create a new layout template from a tag set', :js do login_user user - visit admin_tag_set_path(tag_set_1) + visit tag_set_path(tag_set_1) expect(page).to have_content 'Test tag set 1' click_on 'Create a new tag layout template from this tag set' expect(page).to have_content 'Tag Layout Template New' diff --git a/spec/features/admin/tag_set_spec.rb b/spec/features/tag_set_spec.rb similarity index 97% rename from spec/features/admin/tag_set_spec.rb rename to spec/features/tag_set_spec.rb index cdc23d0233..c210cf54de 100644 --- a/spec/features/admin/tag_set_spec.rb +++ b/spec/features/tag_set_spec.rb @@ -15,7 +15,7 @@ it 'view tag sets and create a new valid one' do login_user user - visit admin_tag_sets_path + visit tag_sets_path expect(page).to have_content 'Listing Tag Sets' click_on 'Create a new Tag Set' expect(page).to have_content 'New Tag Set' @@ -34,7 +34,7 @@ create(:tag_set, name: 'Test tag set') login_user user - visit admin_tag_sets_path + visit tag_sets_path expect(page).to have_content 'Listing Tag Sets' click_on 'Create a new Tag Set' expect(page).to have_content 'New Tag Set' diff --git a/spec/models/ability_spec.rb b/spec/models/ability_spec.rb index 46848c4edc..6aa59c748b 100644 --- a/spec/models/ability_spec.rb +++ b/spec/models/ability_spec.rb @@ -97,6 +97,7 @@ Submission => %i[create read update new order_fields study_assets edit], TagGroup => %i[read], TagLayoutTemplate => %i[read], + TagSet => %i[read], User => %i[edit read projects study_reports print_swipecard] } end