-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4286 from sanger/Y24-221-tag-set-pages
Y24-221 - Adds tag set pages
- Loading branch information
Showing
15 changed files
with
292 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# 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 | ||
|
||
def new | ||
@tag_set = TagSet.new | ||
|
||
respond_to { |format| format.html } | ||
end | ||
|
||
def create | ||
@tag_set = TagSet.new(tag_set_params) | ||
|
||
respond_to do |format| | ||
if @tag_set.save | ||
flash[:notice] = 'Tag Set was successfully created.' | ||
format.html { redirect_to tag_set_path(@tag_set) } | ||
else | ||
format.html { render action: :new } | ||
end | ||
end | ||
end | ||
|
||
def tag_set_params | ||
params.require(:tag_set).permit(:name, :tag_group_id, :tag2_group_id) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
|
||
<div class="page-header"><h1>Listing Tag Sets</h1></div> | ||
|
||
<table class="table"> | ||
<thead> | ||
<th>Name</th> | ||
<th>Tag group (i7)</th> | ||
<th>Tag group (i5)</th> | ||
<th></th> | ||
</thead> | ||
<tbody> | ||
<% for tag_set in @tag_sets %> | ||
<tr> | ||
<td><%= tag_set.name %></td> | ||
<td><%= tag_set.tag_group.name %></td> | ||
<td><%= tag_set.tag2_group&.name %></td> | ||
<td><%= link_to 'Show', tag_set_path(tag_set.id) %></td> | ||
</tr> | ||
<% end %> | ||
</tbody> | ||
</table> | ||
|
||
|
||
<% if can? :create, TagSet %> | ||
<%= link_to 'Create a new Tag Set', new_tag_set_path %> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
|
||
<div class="page-header"><h1>New Tag Set</h1></div> | ||
|
||
<%= form_for @tag_set, url: tag_sets_path do |f| %> | ||
<%= render_error_messages(@tag_set) %> | ||
<div class='form-group'> | ||
<%= f.label :name, 'Tag Set name' %><br> | ||
<%= f.text_field :name, class: 'form-control' %> | ||
</div> | ||
|
||
<div class="form-group"> | ||
<%= f.label :tag_group_id, 'Tag Group (i7)' %><br/> | ||
<%= f.select(:tag_group_id, TagGroup.pluck(:name, :id), { prompt: 'Unspecified' }, class: 'form-control select2' )%> | ||
</div> | ||
|
||
<div class="form-group"> | ||
<%= f.label :tag2_group_id, 'Tag Group (i5)' %><br/> | ||
<%= f.select(:tag2_group_id, TagGroup.pluck(:name, :id), { prompt: 'Unspecified' }, class: 'form-control select2' )%> | ||
</div> | ||
|
||
<div class="form-group actions-group"> | ||
<%= f.submit('Create tag set', class: 'btn btn-success') %> | ||
</div> | ||
<% end %> | ||
<%= link_to 'Back to tag sets list', tag_sets_path %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<% add :menu, "All Tag Sets" => tag_sets_path(@asset) %> | ||
<%= page_title('Tag Set', @tag_set.name) %> | ||
|
||
<dl> | ||
<dt>Name</dt><dd><%= @tag_set.name %></dd> | ||
<dt>Tag group (i7)</dt><dd><%= link_to @tag_set.tag_group.name, @tag_set.tag_group %></dd> | ||
<dt>Tag group (i5)</dt><dd><%= @tag_set.tag2_group ? (link_to @tag_set.tag2_group&.name, @tag_set.tag2_group) : 'None'%></dd> | ||
</dl> | ||
|
||
<br> | ||
<% 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) %> | ||
<br> | ||
<% end %> | ||
<%= link_to 'Back to tag sets list', tag_sets_path %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
|
||
RSpec.describe 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 '#new' do | ||
before { get :new } | ||
|
||
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 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 | ||
|
||
context 'when a non-admin' do | ||
before { session[:user] = create :user } | ||
|
||
describe '#index' do | ||
it 'redirects' do | ||
get :index | ||
expect(response).to have_http_status(:success) | ||
expect(response).to render_template('index') | ||
end | ||
end | ||
|
||
describe '#new' do | ||
it 'redirects' do | ||
get :new | ||
expect(response).to redirect_to('/') | ||
end | ||
end | ||
|
||
describe '#show' do | ||
it 'redirects' do | ||
tag_set = create(:tag_set) | ||
get :show, params: { id: tag_set.id } | ||
expect(response).to have_http_status(:success) | ||
expect(response).to render_template('show') | ||
end | ||
end | ||
|
||
describe '#create' do | ||
it 'redirects' do | ||
post :create, params: attributes_for(:tag_set) | ||
expect(response).to redirect_to('/') | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters