From a59ef10e446b2a247ad8aa50e0c86e756ec5ad92 Mon Sep 17 00:00:00 2001 From: kikito Date: Wed, 12 Aug 2015 18:26:12 +0200 Subject: [PATCH] adds organization controller, with views and tests --- .../moderation/organizations_controller.rb | 25 ++++++++ .../moderation/organizations/index.html.erb | 31 ++++++++++ config/locales/moderation.en.yml | 9 ++- config/locales/moderation.es.yml | 10 +++- config/routes.rb | 6 ++ .../features/moderation/organizations_spec.rb | 57 +++++++++++++++++++ 6 files changed, 136 insertions(+), 2 deletions(-) create mode 100644 app/controllers/moderation/organizations_controller.rb create mode 100644 app/views/moderation/organizations/index.html.erb create mode 100644 spec/features/moderation/organizations_spec.rb diff --git a/app/controllers/moderation/organizations_controller.rb b/app/controllers/moderation/organizations_controller.rb new file mode 100644 index 000000000..4788d3aa2 --- /dev/null +++ b/app/controllers/moderation/organizations_controller.rb @@ -0,0 +1,25 @@ +class Moderation::OrganizationsController < Moderation::BaseController + + before_filter :load_organizations, only: :index + load_and_authorize_resource class: 'User' + + def index + end + + def verify_organization + @organization.update(organization_verified_at: Time.now) + redirect_to action: :index + end + + def reject_organization + @organization.update(organization_rejected_at: Time.now) + redirect_to action: :index + end + + private + + def load_organizations + @organizations = User.organizations.order(:organization_name, :email) + end + +end diff --git a/app/views/moderation/organizations/index.html.erb b/app/views/moderation/organizations/index.html.erb new file mode 100644 index 000000000..3f1d833b6 --- /dev/null +++ b/app/views/moderation/organizations/index.html.erb @@ -0,0 +1,31 @@ +

<%= t('moderation.organizations.index.title') %>

+ + +<% @organizations.each do |organization| %> + + + + + <% if organization.verified_organization? %> + + <% end %> + <% if can? :verify_organization, organization %> + + <% end %> + <% if organization.rejected_organization? %> + + <% end %> + <% if can? :reject_organization, organization %> + + <% end %> + +<% end %> +
<%= organization.organization_name %><%= organization.email %><%= organization.phone_number %><%= t('moderation.organizations.index.verified') %><%= link_to t('moderation.organizations.index.verify'), + verify_organization_moderation_organization_path(organization), + method: :put + %> + <%= t('moderation.organizations.index.rejected') %><%= link_to t('moderation.organizations.index.reject'), + reject_organization_moderation_organization_path(organization), + method: :put + %> +
diff --git a/config/locales/moderation.en.yml b/config/locales/moderation.en.yml index f6cf170e6..c3a765104 100644 --- a/config/locales/moderation.en.yml +++ b/config/locales/moderation.en.yml @@ -2,4 +2,11 @@ en: moderation: dashboard: index: - title: Moderation \ No newline at end of file + title: Moderation + organizations: + index: + title: Organizations + verify: Verify + reject: Reject + verified: Verified + rejected: Rejected diff --git a/config/locales/moderation.es.yml b/config/locales/moderation.es.yml index d54710977..958bd7c75 100644 --- a/config/locales/moderation.es.yml +++ b/config/locales/moderation.es.yml @@ -2,4 +2,12 @@ es: moderation: dashboard: index: - title: Moderación \ No newline at end of file + title: Moderación + organizations: + index: + title: Organizaciones + verify: Verificar + reject: Rechazar + verified: Verificado + rejected: Rechazado + diff --git a/config/routes.rb b/config/routes.rb index 74179ba2a..87eceda55 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -27,6 +27,12 @@ Rails.application.routes.draw do namespace :moderation do root to: "dashboard#index" + resources :organizations, only: :index do + member do + put :verify_organization + put :reject_organization + end + end end # Example of regular route: diff --git a/spec/features/moderation/organizations_spec.rb b/spec/features/moderation/organizations_spec.rb new file mode 100644 index 000000000..9c07a2b9c --- /dev/null +++ b/spec/features/moderation/organizations_spec.rb @@ -0,0 +1,57 @@ +require 'rails_helper' + +feature 'Moderations::Organizations' do + + + background do + moderator = create(:user) + create(:moderator, user: moderator) + + login_as(moderator) + end + + scenario "pending organizations have links to verify and reject" do + organization = create(:organization) + + visit moderation_organizations_path + expect(page).to have_selector(:link_or_button, 'Verify') + expect(page).to have_selector(:link_or_button, 'Reject') + + click_on 'Verify' + expect(current_path).to eq(moderation_organizations_path) + expect(page).to have_content ('Verified') + + expect(organization.reload.verified_organization?).to eq(true) + end + + scenario "verified organizations have link to reject" do + organization = create(:organization, organization_verified_at: Time.now) + + visit moderation_organizations_path + expect(page).to have_content ('Verified') + expect(page).to_not have_selector(:link_or_button, 'Verify') + expect(page).to have_selector(:link_or_button, 'Reject') + + click_on 'Reject' + expect(current_path).to eq(moderation_organizations_path) + expect(page).to have_content ('Rejected') + + expect(organization.reload.rejected_organization?).to eq(true) + end + + scenario "rejected organizations have link to verify" do + organization = create(:organization, organization_rejected_at: Time.now) + + visit moderation_organizations_path + expect(page).to have_content ('Rejected') + expect(page).to have_selector(:link_or_button, 'Verify') + expect(page).to_not have_selector(:link_or_button, 'Reject') + + click_on 'Verify' + expect(current_path).to eq(moderation_organizations_path) + expect(page).to have_content ('Verified') + + expect(organization.reload.verified_organization?).to eq(true) + end + +end