11 changed files with 170 additions and 2 deletions
@ -0,0 +1,31 @@ |
|||||||
|
ActiveAdmin.register Organisation do |
||||||
|
permit_params do |
||||||
|
permitted = %i[name |
||||||
|
phone |
||||||
|
org_type |
||||||
|
address_line1 |
||||||
|
address_line2 |
||||||
|
postcode |
||||||
|
local_authorities |
||||||
|
holds_own_stock |
||||||
|
other_stock_owners |
||||||
|
managing_agents] |
||||||
|
permitted |
||||||
|
end |
||||||
|
|
||||||
|
index do |
||||||
|
selectable_column |
||||||
|
id_column |
||||||
|
column :name |
||||||
|
column :org_type |
||||||
|
column "Address Line 1", :address_line1 |
||||||
|
column "Address Line 2", :address_line2 |
||||||
|
column :postcode |
||||||
|
column "Phone Number", :phone |
||||||
|
column :local_authorities |
||||||
|
column :holds_own_stock |
||||||
|
column :other_stock_owners |
||||||
|
column :managing_agents |
||||||
|
actions |
||||||
|
end |
||||||
|
end |
@ -0,0 +1,3 @@ |
|||||||
|
class Organisation < ApplicationRecord |
||||||
|
has_many :users |
||||||
|
end |
@ -0,0 +1,18 @@ |
|||||||
|
class CreateOrganisations < ActiveRecord::Migration[6.1] |
||||||
|
def change |
||||||
|
create_table :organisations do |t| |
||||||
|
t.string :name |
||||||
|
t.integer :phone |
||||||
|
t.integer :org_type |
||||||
|
t.string :address_line1 |
||||||
|
t.string :address_line2 |
||||||
|
t.string :postcode |
||||||
|
t.string :local_authorities |
||||||
|
t.boolean :holds_own_stock |
||||||
|
t.string :other_stock_owners |
||||||
|
t.string :managing_agents |
||||||
|
|
||||||
|
t.timestamps |
||||||
|
end |
||||||
|
end |
||||||
|
end |
@ -0,0 +1,15 @@ |
|||||||
|
class UserBelongsToOrganisation < ActiveRecord::Migration[6.1] |
||||||
|
def up |
||||||
|
change_table :users, bulk: true do |t| |
||||||
|
t.remove :organisation |
||||||
|
t.belongs_to :organisation |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
def down |
||||||
|
change_table :users, bulk: true do |t| |
||||||
|
t.remove :organisation_id |
||||||
|
t.column :organisation, :string |
||||||
|
end |
||||||
|
end |
||||||
|
end |
@ -0,0 +1,43 @@ |
|||||||
|
require "rails_helper" |
||||||
|
require_relative "../../support/devise" |
||||||
|
|
||||||
|
describe Admin::OrganisationsController, type: :controller do |
||||||
|
render_views |
||||||
|
let(:page) { Capybara::Node::Simple.new(response.body) } |
||||||
|
let(:resource_title) { "Organisations" } |
||||||
|
let(:valid_session) { {} } |
||||||
|
let!(:organisation) { FactoryBot.create(:organisation) } |
||||||
|
login_admin_user |
||||||
|
|
||||||
|
describe "Organisations" do |
||||||
|
before do |
||||||
|
get :index, session: valid_session |
||||||
|
end |
||||||
|
|
||||||
|
it "returns a table of admin users" do |
||||||
|
expect(page).to have_content(resource_title) |
||||||
|
expect(page).to have_table("index_table_organisations") |
||||||
|
expect(page).to have_link(organisation.id.to_s) |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
describe "Create admin users" do |
||||||
|
let(:params) { { organisation: { name: "DLUHC" } } } |
||||||
|
|
||||||
|
it "creates a organisation" do |
||||||
|
expect { post :create, session: valid_session, params: params }.to change(Organisation, :count).by(1) |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
describe "Update organisation" do |
||||||
|
before do |
||||||
|
get :edit, session: valid_session, params: { id: organisation.id } |
||||||
|
end |
||||||
|
|
||||||
|
it "creates a new admin users" do |
||||||
|
expect(page).to have_field("organisation_name") |
||||||
|
expect(page).to have_field("organisation_org_type") |
||||||
|
expect(page).to have_field("organisation_phone") |
||||||
|
end |
||||||
|
end |
||||||
|
end |
@ -0,0 +1,11 @@ |
|||||||
|
FactoryBot.define do |
||||||
|
factory :organisation do |
||||||
|
name { "DLUHC" } |
||||||
|
org_type { 1 } |
||||||
|
address_line1 { "2 Marsham Street" } |
||||||
|
address_line2 { "London" } |
||||||
|
postcode { "SW1P 4DF" } |
||||||
|
created_at { Time.zone.now } |
||||||
|
updated_at { Time.zone.now } |
||||||
|
end |
||||||
|
end |
@ -0,0 +1,16 @@ |
|||||||
|
require "rails_helper" |
||||||
|
|
||||||
|
RSpec.describe Organisation, type: :model do |
||||||
|
describe "#new" do |
||||||
|
let!(:user) { FactoryBot.create(:user) } |
||||||
|
let(:organisation) { Organisation.first } |
||||||
|
|
||||||
|
it "has expected fields" do |
||||||
|
expect(organisation.attribute_names).to include("name", "phone", "org_type") |
||||||
|
end |
||||||
|
|
||||||
|
it "has users" do |
||||||
|
expect(organisation.users.first).to eq(user) |
||||||
|
end |
||||||
|
end |
||||||
|
end |
@ -0,0 +1,12 @@ |
|||||||
|
require "rails_helper" |
||||||
|
|
||||||
|
RSpec.describe User, type: :model do |
||||||
|
describe "#new" do |
||||||
|
let(:user) { FactoryBot.create(:user) } |
||||||
|
let(:organisation) { Organisation.first } |
||||||
|
|
||||||
|
it "belongs to an organisation" do |
||||||
|
expect(user.organisation).to eq(organisation) |
||||||
|
end |
||||||
|
end |
||||||
|
end |
Loading…
Reference in new issue