From 55db7adfcad2c538063cf26ac1aab8eb3dd72ccb Mon Sep 17 00:00:00 2001 From: baarkerlounger Date: Wed, 24 Nov 2021 17:23:06 +0000 Subject: [PATCH] Add create specs --- app/models/form/question.rb | 12 ++++++------ db/schema.rb | 2 +- .../controllers/admin/admin_users_controller_spec.rb | 10 +++++++++- spec/controllers/admin/case_logs_controller_spec.rb | 6 ++++++ spec/controllers/admin/dashboard_controller_spec.rb | 4 ++-- spec/factories/admin_user.rb | 1 - 6 files changed, 24 insertions(+), 11 deletions(-) diff --git a/app/models/form/question.rb b/app/models/form/question.rb index 2362441c8..c4fe5284b 100644 --- a/app/models/form/question.rb +++ b/app/models/form/question.rb @@ -33,12 +33,6 @@ class Form::Question !!readonly end - def conditional_on - @conditional_on ||= form.conditional_question_conditions.select do |condition| - condition[:to] == id - end - end - def enabled?(case_log) return true if conditional_on.blank? @@ -61,6 +55,12 @@ private answer.join(", ") end + def conditional_on + @conditional_on ||= form.conditional_question_conditions.select do |condition| + condition[:to] == id + end + end + def evaluate_condition(condition, case_log) case page.questions.find { |q| q.id == condition[:from] }.type when "numeric" diff --git a/db/schema.rb b/db/schema.rb index 408d07b07..dc5154c56 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -98,6 +98,7 @@ ActiveRecord::Schema.define(version: 2021_11_19_120910) do t.integer "tcharge" t.integer "layear" t.integer "lawaitlist" + t.string "property_postcode" t.integer "reasonpref" t.string "reasonable_preference_reason" t.integer "cbl" @@ -162,7 +163,6 @@ ActiveRecord::Schema.define(version: 2021_11_19_120910) do t.datetime "sale_completion_date" t.datetime "startdate" t.integer "armedforces" - t.string "property_postcode" t.index ["discarded_at"], name: "index_case_logs_on_discarded_at" end diff --git a/spec/controllers/admin/admin_users_controller_spec.rb b/spec/controllers/admin/admin_users_controller_spec.rb index 12ca2da6c..33722cff4 100644 --- a/spec/controllers/admin/admin_users_controller_spec.rb +++ b/spec/controllers/admin/admin_users_controller_spec.rb @@ -8,7 +8,7 @@ describe Admin::AdminUsersController, type: :controller do let(:valid_session) { {} } login_admin_user - describe "Get case logs" do + describe "Get admin users" do before do get :index, session: valid_session end @@ -19,4 +19,12 @@ describe Admin::AdminUsersController, type: :controller do expect(page).to have_link(AdminUser.first.id.to_s) end end + + describe "Create admin users" do + let(:params) { { admin_user: { email: "test2@example.com", password: "pAssword1" } } } + + it "creates a new admin users" do + expect { post :create, session: valid_session, params: params }.to change(AdminUser, :count).by(1) + end + end end diff --git a/spec/controllers/admin/case_logs_controller_spec.rb b/spec/controllers/admin/case_logs_controller_spec.rb index ba56f64ed..1ffec1073 100644 --- a/spec/controllers/admin/case_logs_controller_spec.rb +++ b/spec/controllers/admin/case_logs_controller_spec.rb @@ -20,4 +20,10 @@ describe Admin::CaseLogsController, type: :controller do expect(page).to have_link(case_log.id.to_s) end end + + describe "Create case logs" do + it "creates a new case log" do + expect { post :create, session: valid_session }.to change(CaseLog, :count).by(1) + end + end end diff --git a/spec/controllers/admin/dashboard_controller_spec.rb b/spec/controllers/admin/dashboard_controller_spec.rb index 37efbcf12..7568babb3 100644 --- a/spec/controllers/admin/dashboard_controller_spec.rb +++ b/spec/controllers/admin/dashboard_controller_spec.rb @@ -26,14 +26,14 @@ describe Admin::DashboardController, type: :controller do it "returns a panel of in progress case logs" do panel_xpath = "//div[@class='panel' and .//h3[contains(., 'Total case logs in progress')]]" - panel_content_xpath = panel_xpath + "//div[@class='panel_contents' and .//p[contains(., 2)]]" + panel_content_xpath = "#{panel_xpath}//div[@class='panel_contents' and .//p[contains(., 2)]]" expect(page).to have_xpath(panel_xpath) expect(page).to have_xpath(panel_content_xpath) end it "returns a panel of completed case logs" do panel_xpath = "//div[@class='panel' and .//h3[contains(., 'Total case logs completed')]]" - panel_content_xpath = panel_xpath + "//div[@class='panel_contents' and .//p[contains(., 1)]]" + panel_content_xpath = "#{panel_xpath}//div[@class='panel_contents' and .//p[contains(., 1)]]" expect(page).to have_xpath(panel_xpath) expect(page).to have_xpath(panel_content_xpath) end diff --git a/spec/factories/admin_user.rb b/spec/factories/admin_user.rb index 84c3bbbbe..083e24450 100644 --- a/spec/factories/admin_user.rb +++ b/spec/factories/admin_user.rb @@ -1,6 +1,5 @@ FactoryBot.define do factory :admin_user do - sequence(:id) { |i| i } email { "admin@example.com" } password { "pAssword1" } created_at { Time.zone.now }