Browse Source

Add create specs

pull/108/head
baarkerlounger 4 years ago
parent
commit
55db7adfca
  1. 12
      app/models/form/question.rb
  2. 2
      db/schema.rb
  3. 10
      spec/controllers/admin/admin_users_controller_spec.rb
  4. 6
      spec/controllers/admin/case_logs_controller_spec.rb
  5. 4
      spec/controllers/admin/dashboard_controller_spec.rb
  6. 1
      spec/factories/admin_user.rb

12
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"

2
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

10
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

6
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

4
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

1
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 }

Loading…
Cancel
Save