Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/edit mq assessments vol1 #92

Merged
merged 2 commits into from
Nov 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion app/admin/mq_assessments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@

decorate_with MQ::AssessmentDecorator

actions :all, except: [:new, :edit, :create, :update]
actions :all, except: [:new, :create]

permit_params :assessment_date, :publication_date, :company_id, :notes, :level

filter :assessment_date
filter :publication_date, as: :select, collection: proc { MQ::Assessment.all_publication_dates }
Expand Down Expand Up @@ -61,6 +63,8 @@
active_admin_comments
end

form partial: 'form'

index do
column :title, &:title_link
column :assessment_date
Expand Down
2 changes: 2 additions & 0 deletions app/models/mq/assessment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ def status_description_short
end

def questions
return unless self[:questions].present?

@questions ||= self[:questions].each_with_index.map do |q_hash, index|
MQ::Question.new(q_hash.merge(number: index + 1))
end
Expand Down
16 changes: 16 additions & 0 deletions app/views/admin/mq_assessments/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<%= semantic_form_for [:admin, resource], builder: ActiveAdmin::FormBuilder, html: {'data-controller' => 'check-modified'} do |f| %>
<%= f.semantic_errors(*f.object.errors.keys) %>

<%= f.inputs do %>
<%= f.input :company %>
<%= f.input :assessment_date %>
<%= f.input :publication_date %>
<%= f.input :level, as: :select, collection: MQ::Assessment::LEVELS %>
<%= f.input :notes %>
<% end %>

<%= f.actions do %>
<%= f.action :submit %>
<%= f.action :cancel, :wrapper_html => { :class => 'cancel' } %>
<% end %>
<% end %>
46 changes: 46 additions & 0 deletions spec/controllers/admin/mq_assessments_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

RSpec.describe Admin::MQAssessmentsController, type: :controller do
let(:admin) { create(:admin_user) }
let(:company) { create(:company) }
let!(:mq_assessment) { create(:mq_assessment) }

before { sign_in admin }
Expand All @@ -17,4 +18,49 @@

it { is_expected.to be_successful }
end

xdescribe 'GET new' do
subject { get :new }

it { is_expected.to be_successful }
end

describe 'GET edit' do
subject { get :edit, params: {id: mq_assessment.id} }

it { is_expected.to be_successful }
end

xdescribe 'POST create' do
context 'with valid params' do
let(:valid_attributes) { attributes_for(:mq_assessment, company_id: company.id) }

subject { post :create, params: {mq_assessment: valid_attributes} }

it 'creates a new Assessment' do
expect { subject }.to change(MQ::Assessment, :count).by(1)

last_created = MQ::Assessment.order(:created_at).last

# for now update everything except questions
expect(last_created).to have_attributes(valid_attributes.except(:questions))
end

it 'redirects to the created Assessment' do
expect(subject).to redirect_to(admin_mq_assessment_path(MQ::Assessment.order(:created_at).last))
end
end

context 'with invalid params' do
let(:invalid_attributes) { attributes_for(:mq_assessment, company_id: company.id, publication_date: nil) }

subject { post :create, params: {mq_assessment: invalid_attributes} }

it { is_expected.to be_successful }

it 'invalid_attributes do not create a Assessment' do
expect { subject }.not_to change(MQ::Assessment, :count)
end
end
end
end
4 changes: 2 additions & 2 deletions spec/factories/mq_assessments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
factory :mq_assessment, class: MQ::Assessment do
association :company

assessment_date { 1.year.ago }
publication_date { 11.months.ago }
assessment_date { 1.year.ago.to_date }
publication_date { 11.months.ago.to_date }

level { '1' }
notes { 'Some notes' }
Expand Down