Skip to content

Commit

Permalink
Merge pull request #6379 from saraycp/project_attributes
Browse files Browse the repository at this point in the history
Project attributes on bootstrap
  • Loading branch information
Ana06 committed Dec 5, 2018
2 parents 8e2f23a + 80b8e60 commit dedc37d
Show file tree
Hide file tree
Showing 10 changed files with 102 additions and 38 deletions.
6 changes: 3 additions & 3 deletions src/api/app/controllers/webui/attribute_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Webui::AttributeController < Webui::WebuiController
def index
@attributes = @container.attribs.includes(:issues, :values, attrib_type: [:attrib_namespace]).sort_by(&:fullname)

switch_to_webui2 if @container.is_a?(Package)
switch_to_webui2
end

def new
Expand All @@ -25,7 +25,7 @@ def new

authorize @attribute, :create?

switch_to_webui2 if @container.is_a?(Package)
switch_to_webui2
end

def edit
Expand All @@ -40,7 +40,7 @@ def edit
(value_count - values_length).times { @attribute.values.build(attrib: @attribute) }
end

switch_to_webui2 if @container.is_a?(Package)
switch_to_webui2
end

def create
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
= render partial: 'webui/package/breadcrumb_items'
= render partial: "webui/#{@container.model_name.singular}/breadcrumb_items"

- if current_page?(index_attribs_path)
%li.breadcrumb-item.active{ 'aria-current' => 'page' }
Expand All @@ -7,8 +7,9 @@
%li.breadcrumb-item
= link_to('Attributes', index_attribs_path)
%li.breadcrumb-item.active{ 'aria-current' => 'page' }
- case request.path
- when new_attribs_path(@project, @package)
- if controller_name == 'attributes'
- case action_name
- when 'new'
Add
- when edit_attribs_path(@project, @package, @attribute.fullname)
- when 'edit'
= @attribute.fullname
3 changes: 1 addition & 2 deletions src/api/app/views/webui2/webui/attribute/edit.html.haml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
- @pagetitle = "Edit Attribute #{@attribute.fullname} on #{@container.class} #{@container.name}"

.card
= render(partial: 'webui/package/tabs', locals: { project: @project, package: @package })
= render(partial: "webui/#{@container.model_name.singular}/tabs", locals: { project: @project, package: @package })

.card-body
%h3= @pagetitle
Expand Down
12 changes: 6 additions & 6 deletions src/api/app/views/webui2/webui/attribute/index.html.haml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
- @pagetitle = "Attributes of #{@package} (Project #{@project})"
- @pagetitle = "Attributes of #{@package ? "#{@package} (Project #{@project})" : "Project #{@project}"}"

.card
= render(partial: 'webui/package/tabs', locals: { project: @project, package: @package })
= render(partial: "webui/#{@container.model_name.singular}/tabs", locals: { project: @project, package: @package })

.card-body
%h3= @pagetitle
Expand All @@ -11,7 +11,7 @@
%tr
%th.w-50 Attributes
%th.w-25 Values
- if policy(@package).update?
- if policy(@container).update?
%th Actions
%tbody
- @attributes.each do |attribute|
Expand All @@ -25,21 +25,21 @@
%pre.d-inline= v.value
- unless attribute.issues.empty?
%li= attribute.issues.map(&:name).to_sentence
- if policy(@package).update?
- if policy(@container).update?
%td
- if attribute.values_editable?
= link_to(edit_attribs_path(project: @project.name, package: @package, attribute: attribute.fullname), title: 'Edit values') do
%i.fas.fa-edit.text-secondary
= link_to('#', data: { toggle: 'modal', target: "#delete-attribute-modal-#{attribute.id}" },
title: 'Delete attribute') do
%i.fas.fa-times-circle.text-danger
- if policy(@package).update?
- if policy(@container).update?
= render(partial: 'delete_dialog', locals: { attribute: attribute })
- else
%p
%em No attributes set

- if policy(@package).update?
- if policy(@container).update?
%p
= link_to(new_attribs_path(project: @project.name, package: @package), title: 'Add a new attribute') do
%i.fas.fa-plus-circle.text-primary
Expand Down
2 changes: 1 addition & 1 deletion src/api/app/views/webui2/webui/attribute/new.html.haml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
- @pagetitle = 'Add Attribute'

.card
= render(partial: 'webui/package/tabs', locals: { project: @project, package: @package })
= render(partial: "webui/#{@container.model_name.singular}/tabs", locals: { project: @project, package: @package })

.card-body
%h3= @pagetitle
Expand Down
55 changes: 55 additions & 0 deletions src/api/spec/bootstrap/features/webui/attributes_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
require 'browser_helper'

RSpec.feature 'Bootstrap_Attributes', type: :feature, js: true do
let!(:user) { create(:confirmed_user) }
let!(:attribute_type) { create(:attrib_type, name: 'MyImageTemplates') }
let!(:attribute) { create(:attrib, project: user.home_project) }

context 'for a project' do
context 'without permissions' do
let!(:other_user) { create(:confirmed_user) }

scenario 'it is not possible to add an attribute, the link is not shown' do
login other_user

visit index_attribs_path(project: user.home_project_name)
expect(page).not_to have_content('Add a new attribute')
end
end

context 'with permissions' do
scenario 'remove attribute' do
login user

visit index_attribs_path(project: user.home_project_name)
click_link 'Delete attribute'
expect(find("#delete-attribute-modal-#{attribute.id}")).to have_text('Delete attribute?')
within("#delete-attribute-modal-#{attribute.id} .modal-footer") do
expect(page).to have_button('Delete')
click_button('Delete')
end
expect(page).to have_css('#flash')
within('#flash') do
expect(page).to have_text('Attribute sucessfully deleted!')
end
end
end
end

context 'for a project with a package' do
let!(:package) do
create(:package, project: user.home_project)
end

scenario 'add attribute with values' do
login user

add_attribute_with_values(package)
expect(page).to have_content('Attribute was successfully updated.')

visit index_attribs_path(project: user.home_project_name, package: package.name)
attribute_type_value = page.all('#attributes tr td', exact_text: attribute_type.fullname)[0].sibling('td', match: :first).text
expect(attribute_type_value).to eq("test\n2nd line\ntest 1")
end
end
end
1 change: 1 addition & 0 deletions src/api/spec/browser_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
# helper methods for authentication in features tests
require 'support/features/features_authentication'
require 'support/features/features_bootstrap'
require 'support/features/features_attribute'

# Shared examples. Per recommendation of RSpec,
# https://www.relishapp.com/rspec/rspec-core/v/2-12/docs/example-groups/shared-examples
Expand Down
24 changes: 3 additions & 21 deletions src/api/spec/features/webui/attributes_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,6 @@
# AttribTypes are part of the seeds, so we can reuse them
let!(:attribute_type) { AttribType.find_by(name: 'ImageTemplates') }

def add_attribute_with_values(package = nil)
visit index_attribs_path(project: user.home_project_name, package: package.try(:name))
click_link('Add a new attribute')
expect(page).to have_text('Add Attribute')
find('select#attrib_attrib_type_id').select(attribute_type.name)
click_button('Add')
expect(page).to have_content('Attribute was successfully created.')

# FIXME: With the cocoon gem, the first click is somehow not registered... but only when testing in Capybara
click_link('Add a value')
fill_in 'Value', with: 'test 1', match: :first

click_link('Add a value')
# Workaround to enter data into second textfield
within('div.nested-fields:nth-of-type(2)') do
fill_in 'Value', with: "test\n2nd line"
end

click_button('Save')
end

describe 'for a project without packages' do
scenario 'add attribute with values' do
login user
Expand Down Expand Up @@ -54,6 +33,7 @@ def add_attribute_with_values(package = nil)
let!(:other_user) { create(:confirmed_user) }

scenario 'add attribute with values should fail' do
skip_if_bootstrap
login other_user

visit index_attribs_path(project: user.home_project_name)
Expand All @@ -78,6 +58,8 @@ def add_attribute_with_values(package = nil)
end

scenario 'remove attribute' do
skip_if_bootstrap

login user
attribute = create(:attrib, project_id: user.home_project.id)

Expand Down
2 changes: 1 addition & 1 deletion src/api/spec/features/webui/projects_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@
click_button('Add')

expect(page).to have_text('Attribute was successfully created.')
expect(find('table tr.attribute-values td:first-child')).to have_text('OBS:MaintenanceProject')
expect(find('table tr td:first-child')).to have_text('OBS:MaintenanceProject')
end
end

Expand Down
26 changes: 26 additions & 0 deletions src/api/spec/support/features/features_attribute.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
module FeaturesAttribute
def add_attribute_with_values(package = nil)
visit index_attribs_path(project: user.home_project_name, package: package.try(:name))
click_link('Add a new attribute')
expect(page).to have_text('Add Attribute')
find('select#attrib_attrib_type_id').select("#{attribute_type.attrib_namespace}:#{attribute_type.name}")
click_button('Add')
expect(page).to have_content('Attribute was successfully created.')

# FIXME: With the cocoon gem, the first click is somehow not registered... but only when testing in Capybara
click_link('Add a value')
fill_in 'Value', with: 'test 1', match: :first

click_link('Add a value')
# Workaround to enter data into second textfield
within('div.nested-fields:nth-of-type(2)') do
fill_in 'Value', with: "test\n2nd line"
end

click_button('Save')
end
end

RSpec.configure do |config|
config.include FeaturesAttribute, type: :feature
end

0 comments on commit dedc37d

Please sign in to comment.