From 0c732208311ea7b8c897a9301401191af114eb5f Mon Sep 17 00:00:00 2001 From: baarkerlounger Date: Wed, 8 Sep 2021 16:27:01 +0100 Subject: [PATCH 1/2] Add factorybot --- Gemfile | 1 + Gemfile.lock | 6 ++++++ spec/spec_helper.rb | 8 +++++++- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index c06fdf065..4066943b0 100644 --- a/Gemfile +++ b/Gemfile @@ -28,6 +28,7 @@ group :development, :test do gem "pry-byebug" gem "dotenv-rails" gem "selenium-webdriver" + gem "factory_bot_rails" %w[rspec-core rspec-expectations rspec-mocks rspec-rails rspec-support].each do |lib| gem lib, git: "https://github.com/rspec/#{lib}.git", branch: "main" end diff --git a/Gemfile.lock b/Gemfile.lock index 0cf205e18..b6d1de185 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -134,6 +134,11 @@ GEM dotenv (= 2.7.6) railties (>= 3.2) erubi (1.10.0) + factory_bot (6.2.0) + activesupport (>= 5.0.0) + factory_bot_rails (6.2.0) + factory_bot (~> 6.2.0) + railties (>= 5.0.0) ffi (1.15.4) globalid (0.5.2) activesupport (>= 5.0) @@ -311,6 +316,7 @@ DEPENDENCIES byebug capybara dotenv-rails + factory_bot_rails govuk-components govuk_design_system_formbuilder jbuilder (~> 2.7) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 15a38725b..6cf19332c 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -13,6 +13,9 @@ # it. # # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration + +require "factory_bot" + RSpec.configure do |config| # rspec-expectations config goes here. You can use an alternate # assertion/expectation library such as wrong or the stdlib/minitest @@ -84,11 +87,14 @@ RSpec.configure do |config| # # order dependency and want to debug it, you can fix the order by providing # # the seed, which is printed after each run. # # --seed 1234 - # config.order = :random + config.order = :random # # # Seed global randomization in this process using the `--seed` CLI option. # # Setting this allows you to use `--seed` to deterministically reproduce # # test failures related to randomization by passing the same `--seed` value # # as the one that triggered the failure. # Kernel.srand config.seed + + + config.include FactoryBot::Syntax::Methods end From a73c020658d7e71d95f983d550fe698b949b5783 Mon Sep 17 00:00:00 2001 From: baarkerlounger Date: Wed, 8 Sep 2021 16:28:22 +0100 Subject: [PATCH 2/2] Add a case log --- app/controllers/case_logs_controller.rb | 7 +++++++ app/models/case_log.rb | 3 +++ app/views/case_logs/index.html.erb | 0 app/views/case_logs/show.html.erb | 3 +++ config/routes.rb | 2 ++ db/migrate/20210908122819_add_case_log.rb | 8 ++++++++ db/schema.rb | 24 +++++++++++++++++++++++ spec/factories/case_log.rb | 6 ++++++ spec/features/case_log_spec.rb | 11 +++++++++++ 9 files changed, 64 insertions(+) create mode 100644 app/controllers/case_logs_controller.rb create mode 100644 app/models/case_log.rb create mode 100644 app/views/case_logs/index.html.erb create mode 100644 app/views/case_logs/show.html.erb create mode 100644 db/migrate/20210908122819_add_case_log.rb create mode 100644 db/schema.rb create mode 100644 spec/factories/case_log.rb create mode 100644 spec/features/case_log_spec.rb diff --git a/app/controllers/case_logs_controller.rb b/app/controllers/case_logs_controller.rb new file mode 100644 index 000000000..262fff240 --- /dev/null +++ b/app/controllers/case_logs_controller.rb @@ -0,0 +1,7 @@ +class CaseLogsController < ApplicationController + def index; end + + def show + @case_log = CaseLog.find(params[:id]) + end +end diff --git a/app/models/case_log.rb b/app/models/case_log.rb new file mode 100644 index 000000000..9fd005fb7 --- /dev/null +++ b/app/models/case_log.rb @@ -0,0 +1,3 @@ +class CaseLog < ApplicationRecord + enum status: ["in progress", "submitted"] +end diff --git a/app/views/case_logs/index.html.erb b/app/views/case_logs/index.html.erb new file mode 100644 index 000000000..e69de29bb diff --git a/app/views/case_logs/show.html.erb b/app/views/case_logs/show.html.erb new file mode 100644 index 000000000..5c42fa4db --- /dev/null +++ b/app/views/case_logs/show.html.erb @@ -0,0 +1,3 @@ +

Tasklist for log <%= @case_log.id %>

+ +

This submission is <%= @case_log.status %>

diff --git a/config/routes.rb b/config/routes.rb index 092edea76..c7af26f3f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -3,4 +3,6 @@ Rails.application.routes.draw do get "about", to: "about#index" get "/", to: "test#index" get "form", to: "form#index" + + resources :case_logs end diff --git a/db/migrate/20210908122819_add_case_log.rb b/db/migrate/20210908122819_add_case_log.rb new file mode 100644 index 000000000..f3368b2a4 --- /dev/null +++ b/db/migrate/20210908122819_add_case_log.rb @@ -0,0 +1,8 @@ +class AddCaseLog < ActiveRecord::Migration[6.1] + def change + create_table :case_logs do |t| + t.integer :status, default: 0 + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb new file mode 100644 index 000000000..936791fa2 --- /dev/null +++ b/db/schema.rb @@ -0,0 +1,24 @@ +# This file is auto-generated from the current state of the database. Instead +# of editing this file, please use the migrations feature of Active Record to +# incrementally modify your database, and then regenerate this schema definition. +# +# This file is the source Rails uses to define your schema when running `bin/rails +# db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to +# be faster and is potentially less error prone than running all of your +# migrations from scratch. Old migrations may fail to apply correctly if those +# migrations use external dependencies or application code. +# +# It's strongly recommended that you check this file into your version control system. + +ActiveRecord::Schema.define(version: 2021_09_08_122819) do + + # These are extensions that must be enabled in order to support this database + enable_extension "plpgsql" + + create_table "case_logs", force: :cascade do |t| + t.integer "status", default: 0 + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false + end + +end diff --git a/spec/factories/case_log.rb b/spec/factories/case_log.rb new file mode 100644 index 000000000..cefc12c97 --- /dev/null +++ b/spec/factories/case_log.rb @@ -0,0 +1,6 @@ +FactoryBot.define do + factory :case_log do + id { 342351 } + status { 0 } + end +end diff --git a/spec/features/case_log_spec.rb b/spec/features/case_log_spec.rb new file mode 100644 index 000000000..05bdaa6c1 --- /dev/null +++ b/spec/features/case_log_spec.rb @@ -0,0 +1,11 @@ +require "rails_helper" +RSpec.describe "Test Features" do + let!(:case_log){ FactoryBot.create(:case_log) } + let(:id){ case_log.id } + let(:status) { case_log.status } + + it "Displays a tasklist header" do + visit("/case_logs/342351") + expect(page).to have_content("Tasklist for log 342351") + end +end