diff options
author | Matthew Lemon <y@yulqen.org> | 2023-12-18 19:38:44 +0000 |
---|---|---|
committer | Matthew Lemon <y@yulqen.org> | 2023-12-18 19:38:44 +0000 |
commit | 8185939b2629581dd9264dbbc37f859e19436f31 (patch) | |
tree | fdbc4f11f8d6c911ac7ebc4563254ae5299db603 /spec | |
parent | 1fe9bf5c59ba9d4df5d2c917896348a0e23613a0 (diff) |
wip: stuck on notnull error...
Diffstat (limited to 'spec')
-rw-r--r-- | spec/helpers/organisations_helper_spec.rb | 15 | ||||
-rw-r--r-- | spec/models/organisation_spec.rb | 5 | ||||
-rw-r--r-- | spec/requests/organisations_spec.rb | 135 | ||||
-rw-r--r-- | spec/routing/organisations_routing_spec.rb | 38 | ||||
-rw-r--r-- | spec/views/organisations/edit.html.erb_spec.rb | 22 | ||||
-rw-r--r-- | spec/views/organisations/index.html.erb_spec.rb | 20 | ||||
-rw-r--r-- | spec/views/organisations/new.html.erb_spec.rb | 18 | ||||
-rw-r--r-- | spec/views/organisations/show.html.erb_spec.rb | 14 |
8 files changed, 267 insertions, 0 deletions
diff --git a/spec/helpers/organisations_helper_spec.rb b/spec/helpers/organisations_helper_spec.rb new file mode 100644 index 0000000..85ff232 --- /dev/null +++ b/spec/helpers/organisations_helper_spec.rb @@ -0,0 +1,15 @@ +require 'rails_helper' + +# Specs in this file have access to a helper object that includes +# the OrganisationsHelper. For example: +# +# describe OrganisationsHelper do +# describe "string concat" do +# it "concats two strings with spaces" do +# expect(helper.concat_strings("this","that")).to eq("this that") +# end +# end +# end +RSpec.describe OrganisationsHelper, type: :helper do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/organisation_spec.rb b/spec/models/organisation_spec.rb new file mode 100644 index 0000000..6f6cdca --- /dev/null +++ b/spec/models/organisation_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe Organisation, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/requests/organisations_spec.rb b/spec/requests/organisations_spec.rb new file mode 100644 index 0000000..669d7ec --- /dev/null +++ b/spec/requests/organisations_spec.rb @@ -0,0 +1,135 @@ +require 'rails_helper' + +# This spec was generated by rspec-rails when you ran the scaffold generator. +# It demonstrates how one might use RSpec to test the controller code that +# was generated by Rails when you ran the scaffold generator. +# +# It assumes that the implementation code is generated by the rails scaffold +# generator. If you are using any extension libraries to generate different +# controller code, this generated spec may or may not pass. +# +# It only uses APIs available in rails and/or rspec-rails. There are a number +# of tools you can use to make these specs even more expressive, but we're +# sticking to rails and rspec-rails APIs to keep things simple and stable. + +RSpec.describe "/organisations", type: :request do + + # This should return the minimal set of attributes required to create a valid + # Organisation. As you add validations to Organisation, be sure to + # adjust the attributes here as well. + let(:valid_attributes) { + skip("Add a hash of attributes valid for your model") + } + + let(:invalid_attributes) { + skip("Add a hash of attributes invalid for your model") + } + + describe "GET /index" do + it "renders a successful response" do + Organisation.create! valid_attributes + get organisations_url + expect(response).to be_successful + end + end + + describe "GET /show" do + it "renders a successful response" do + organisation = Organisation.create! valid_attributes + get organisation_url(organisation) + expect(response).to be_successful + end + end + + describe "GET /new" do + it "renders a successful response" do + get new_organisation_url + expect(response).to be_successful + end + end + + describe "GET /edit" do + it "renders a successful response" do + organisation = Organisation.create! valid_attributes + get edit_organisation_url(organisation) + expect(response).to be_successful + end + end + + describe "POST /create" do + context "with valid parameters" do + it "creates a new Organisation" do + expect { + post organisations_url, params: { organisation: valid_attributes } + }.to change(Organisation, :count).by(1) + end + + it "redirects to the created organisation" do + post organisations_url, params: { organisation: valid_attributes } + expect(response).to redirect_to(organisation_url(Organisation.last)) + end + end + + context "with invalid parameters" do + it "does not create a new Organisation" do + expect { + post organisations_url, params: { organisation: invalid_attributes } + }.to change(Organisation, :count).by(0) + end + + + it "renders a response with 422 status (i.e. to display the 'new' template)" do + post organisations_url, params: { organisation: invalid_attributes } + expect(response).to have_http_status(:unprocessable_entity) + end + + end + end + + describe "PATCH /update" do + context "with valid parameters" do + let(:new_attributes) { + skip("Add a hash of attributes valid for your model") + } + + it "updates the requested organisation" do + organisation = Organisation.create! valid_attributes + patch organisation_url(organisation), params: { organisation: new_attributes } + organisation.reload + skip("Add assertions for updated state") + end + + it "redirects to the organisation" do + organisation = Organisation.create! valid_attributes + patch organisation_url(organisation), params: { organisation: new_attributes } + organisation.reload + expect(response).to redirect_to(organisation_url(organisation)) + end + end + + context "with invalid parameters" do + + it "renders a response with 422 status (i.e. to display the 'edit' template)" do + organisation = Organisation.create! valid_attributes + patch organisation_url(organisation), params: { organisation: invalid_attributes } + expect(response).to have_http_status(:unprocessable_entity) + end + + end + end + + describe "DELETE /destroy" do + it "destroys the requested organisation" do + organisation = Organisation.create! valid_attributes + expect { + delete organisation_url(organisation) + }.to change(Organisation, :count).by(-1) + end + + it "redirects to the organisations list" do + organisation = Organisation.create! valid_attributes + delete organisation_url(organisation) + expect(response).to redirect_to(organisations_url) + end + end +end diff --git a/spec/routing/organisations_routing_spec.rb b/spec/routing/organisations_routing_spec.rb new file mode 100644 index 0000000..4892aae --- /dev/null +++ b/spec/routing/organisations_routing_spec.rb @@ -0,0 +1,38 @@ +require "rails_helper" + +RSpec.describe OrganisationsController, type: :routing do + describe "routing" do + it "routes to #index" do + expect(get: "/organisations").to route_to("organisations#index") + end + + it "routes to #new" do + expect(get: "/organisations/new").to route_to("organisations#new") + end + + it "routes to #show" do + expect(get: "/organisations/1").to route_to("organisations#show", id: "1") + end + + it "routes to #edit" do + expect(get: "/organisations/1/edit").to route_to("organisations#edit", id: "1") + end + + + it "routes to #create" do + expect(post: "/organisations").to route_to("organisations#create") + end + + it "routes to #update via PUT" do + expect(put: "/organisations/1").to route_to("organisations#update", id: "1") + end + + it "routes to #update via PATCH" do + expect(patch: "/organisations/1").to route_to("organisations#update", id: "1") + end + + it "routes to #destroy" do + expect(delete: "/organisations/1").to route_to("organisations#destroy", id: "1") + end + end +end diff --git a/spec/views/organisations/edit.html.erb_spec.rb b/spec/views/organisations/edit.html.erb_spec.rb new file mode 100644 index 0000000..bc410f5 --- /dev/null +++ b/spec/views/organisations/edit.html.erb_spec.rb @@ -0,0 +1,22 @@ +require 'rails_helper' + +RSpec.describe "organisations/edit", type: :view do + let(:organisation) { + Organisation.create!( + name: "MyString" + ) + } + + before(:each) do + assign(:organisation, organisation) + end + + it "renders the edit organisation form" do + render + + assert_select "form[action=?][method=?]", organisation_path(organisation), "post" do + + assert_select "input[name=?]", "organisation[name]" + end + end +end diff --git a/spec/views/organisations/index.html.erb_spec.rb b/spec/views/organisations/index.html.erb_spec.rb new file mode 100644 index 0000000..2755a02 --- /dev/null +++ b/spec/views/organisations/index.html.erb_spec.rb @@ -0,0 +1,20 @@ +require 'rails_helper' + +RSpec.describe "organisations/index", type: :view do + before(:each) do + assign(:organisations, [ + Organisation.create!( + name: "Name" + ), + Organisation.create!( + name: "Name" + ) + ]) + end + + it "renders a list of organisations" do + render + cell_selector = Rails::VERSION::STRING >= '7' ? 'div>p' : 'tr>td' + assert_select cell_selector, text: Regexp.new("Name".to_s), count: 2 + end +end diff --git a/spec/views/organisations/new.html.erb_spec.rb b/spec/views/organisations/new.html.erb_spec.rb new file mode 100644 index 0000000..948be9e --- /dev/null +++ b/spec/views/organisations/new.html.erb_spec.rb @@ -0,0 +1,18 @@ +require 'rails_helper' + +RSpec.describe "organisations/new", type: :view do + before(:each) do + assign(:organisation, Organisation.new( + name: "MyString" + )) + end + + it "renders new organisation form" do + render + + assert_select "form[action=?][method=?]", organisations_path, "post" do + + assert_select "input[name=?]", "organisation[name]" + end + end +end diff --git a/spec/views/organisations/show.html.erb_spec.rb b/spec/views/organisations/show.html.erb_spec.rb new file mode 100644 index 0000000..2974e87 --- /dev/null +++ b/spec/views/organisations/show.html.erb_spec.rb @@ -0,0 +1,14 @@ +require 'rails_helper' + +RSpec.describe "organisations/show", type: :view do + before(:each) do + assign(:organisation, Organisation.create!( + name: "Name" + )) + end + + it "renders attributes in <p>" do + render + expect(rendered).to match(/Name/) + end +end |