Skip to content

Commit

Permalink
Fix specs
Browse files Browse the repository at this point in the history
  • Loading branch information
aapomm committed Feb 6, 2025
1 parent bcc28f1 commit b41c3eb
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
7 changes: 5 additions & 2 deletions app/controllers/concerns/qa_states.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@ module QAStates
extend ActiveSupport::Concern

included do
before_action :set_states, only: [:new, :edit]
before_action :set_states, only: [:new, :create, :edit, :update]

before_action :ensure_reviewer, only: [:create, :update, :multiple_update]
end

private

def ensure_reviewer
record_params = self.send("#{controller_name.singularize}_params")
params_method = "#{controller_name.singularize}_params"
return unless self.respond_to?(params_method)

record_params = self.send(params_method)

if (record_params[:state] == 'published' || params[:state] == 'published') &&
!can?(:publish, @issue)
Expand Down
32 changes: 32 additions & 0 deletions spec/support/qa_shared_examples.rb
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,38 @@
end
end

describe 'reviewer role', js: true do
context 'user is not a reviewer' do
before do
allow_any_instance_of(Project).to receive(:reviewers).and_return(User.none)
visit polymorphic_path([current_project, :qa, item_type.to_s.pluralize.to_sym])
end

it 'disables the "published" state option' do
page.find('td.select-checkbox', match: :first).click
click_button 'State'

save_and_open_page

expect(page).to have_css('.dt-button.dropdown-item.disabled', text: 'Published')
end
end

context 'user is a reviewer', focus: true do
before do
allow_any_instance_of(Project).to receive(:reviewers).and_return(User.all)
visit polymorphic_path([current_project, :qa, item_type.to_s.pluralize.to_sym])
end

it 'allows the "published" state option' do
page.find('td.select-checkbox', match: :first).click
click_button 'State'

expect(page).to have_css('.dt-button.dropdown-item', text: 'Published')
end
end
end

def job_params(record)
{
action: 'state_change',
Expand Down

0 comments on commit b41c3eb

Please sign in to comment.