From a6daff85820f5c21b18210df1e3afda9f8486a47 Mon Sep 17 00:00:00 2001 From: James Mason Date: Fri, 16 Mar 2018 12:02:49 -0700 Subject: [PATCH] Add/edit org code of conduct, as admin --- .../admin/organizations_controller.rb | 4 ++- app/views/admin/organizations/_form.html.haml | 9 ++++- app/views/admin/organizations/index.html.haml | 6 +++- ...150_add_code_of_conduct_to_organization.rb | 5 +++ db/schema.rb | 5 +-- spec/features/code_of_conduct_spec.rb | 34 +++++++++++++++++++ 6 files changed, 58 insertions(+), 5 deletions(-) create mode 100644 db/migrate/20180316185150_add_code_of_conduct_to_organization.rb create mode 100644 spec/features/code_of_conduct_spec.rb diff --git a/app/controllers/admin/organizations_controller.rb b/app/controllers/admin/organizations_controller.rb index 8562d61a..aa4f1380 100644 --- a/app/controllers/admin/organizations_controller.rb +++ b/app/controllers/admin/organizations_controller.rb @@ -88,7 +88,9 @@ module Admin end def organization_params - params.require(:organization).permit(:name, :description, :picture) + params.require(:organization).permit( + :name, :description, :picture, :code_of_conduct + ) end end end diff --git a/app/views/admin/organizations/_form.html.haml b/app/views/admin/organizations/_form.html.haml index 048d13e4..fa326431 100644 --- a/app/views/admin/organizations/_form.html.haml +++ b/app/views/admin/organizations/_form.html.haml @@ -1,7 +1,14 @@ = semantic_form_for(@organization, url: (@organization.new_record? ? admin_organizations_path : admin_organization_path(@organization))) do |f| = f.inputs name: 'Organization details' do = f.input :name, as: :string, required: true - = f.input :description, as: :text, input_html: { rows: 10 }, placeholder: 'Decribe about your organization..' + = f.input :description, as: :text, + input_html: { rows: 10, data: { provide: 'markdown-editable' } }, + hint: markdown_hint, + placeholder: 'Decribe about your organization...' + = f.input :code_of_conduct, as: :text, + input_html: { rows: 10, data: { provide: 'markdown-editable' } }, + hint: markdown_hint, + placeholder: 'Rules governing behavior and dispute resolution...' = image_tag f.object.picture.thumb.url if f.object.picture? - if @organization.picture? = image_tag(@organization.picture.thumb.url, width: '20%') diff --git a/app/views/admin/organizations/index.html.haml b/app/views/admin/organizations/index.html.haml index 7226d2a6..ed782677 100644 --- a/app/views/admin/organizations/index.html.haml +++ b/app/views/admin/organizations/index.html.haml @@ -14,16 +14,20 @@ %th Name %th Upcoming Conferences %th Past Conferences + %th Code of Conduct? %th Actions %tbody - @organizations.each do |organization| - %tr + %tr{ id: "organization-#{organization.id}" } %td = organization.name %td = organization.conferences.upcoming.count %td = organization.conferences.past.count + %td.text-center + - unless organization.code_of_conduct.blank? + = fa_icon 'check', title: 'yes' %td .btn-group = link_to 'Admins', admins_admin_organization_path(organization), diff --git a/db/migrate/20180316185150_add_code_of_conduct_to_organization.rb b/db/migrate/20180316185150_add_code_of_conduct_to_organization.rb new file mode 100644 index 00000000..447e0c84 --- /dev/null +++ b/db/migrate/20180316185150_add_code_of_conduct_to_organization.rb @@ -0,0 +1,5 @@ +class AddCodeOfConductToOrganization < ActiveRecord::Migration[5.0] + def change + add_column :organizations, :code_of_conduct, :text + end +end diff --git a/db/schema.rb b/db/schema.rb index 71b47e99..0ea8a9e8 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20180313012253) do +ActiveRecord::Schema.define(version: 20180316185150) do create_table "ahoy_events", force: :cascade do |t| t.integer "visit_id" @@ -303,9 +303,10 @@ ActiveRecord::Schema.define(version: 20180313012253) do end create_table "organizations", force: :cascade do |t| - t.string "name", null: false + t.string "name", null: false t.text "description" t.string "picture" + t.text "code_of_conduct" end create_table "payments", force: :cascade do |t| diff --git a/spec/features/code_of_conduct_spec.rb b/spec/features/code_of_conduct_spec.rb new file mode 100644 index 00000000..2300fe1f --- /dev/null +++ b/spec/features/code_of_conduct_spec.rb @@ -0,0 +1,34 @@ +require 'spec_helper' + +feature 'Code of Conduct:' do + let!(:organization) { create(:organization) } + let(:admin) { create(:admin) } + let(:sample_text) { Faker::Lorem.paragraph } + + context 'on an organization' do + describe 'as admin' do + before { sign_in admin } + + it 'can add and remove' do + visit admin_organizations_path + within "tr#organization-#{organization.id}" do + expect(page).not_to have_css 'i.fa-check' + click_on 'Edit' + end + expect(page).to have_field 'organization[code_of_conduct]', with: '' + fill_in 'organization[code_of_conduct]', with: sample_text + click_on 'Update Organization' + within "tr#organization-#{organization.id}" do + expect(page).to have_css 'i.fa-check' + click_on 'Edit' + end + expect(page).to have_field 'organization[code_of_conduct]', with: sample_text + fill_in 'organization[code_of_conduct]', with: '' + click_on 'Update Organization' + within "tr#organization-#{organization.id}" do + expect(page).not_to have_css 'i.fa-check' + end + end + end + end +end