Permalink
Browse files

Merge pull request #4 from alphagov/user_access_forms_refactoring

User access forms refactoring in prep for the Inside Government requirements
  • Loading branch information...
2 parents 060095f + c706435 commit 7848f12a4f589d4745a33764bcf6b77ab136de95 @jamiecobbett jamiecobbett committed Nov 9, 2012
@@ -0,0 +1,13 @@
+class CreateNewUserRequestsController < ApplicationController
+ def new
+ @formdata = {}
+ prepopulate_organisation_list
+ end
+
+ def create
+ @template = "create_new_user_requests/new"
+
+ @errors = Guard.validationsForCreateUser(params)
+ on_post(params, "create-user")
+ end
+end
@@ -0,0 +1,15 @@
+require 'guard'
+
+class RemoveUserRequestsController < ApplicationController
+ def new
+ @formdata = {}
+ prepopulate_organisation_list
+ end
+
+ def create
+ @template = "remove_user_requests/new"
+
+ @errors = Guard.validationsForDeleteUser(params)
+ on_post(params, "remove-user")
+ end
+end
@@ -1,17 +1,6 @@
require "guard"
class SupportController < ApplicationController
- def create_user
- if request.method == "GET"
- on_get("useraccess/user")
- elsif request.method == "POST"
- @template = "useraccess/user"
-
- @errors = Guard.validationsForCreateUser(params)
- on_post(params, "create-user")
- end
- end
-
def remove_user
if request.method == "GET"
on_get("useraccess/userremove")
@@ -22,13 +22,7 @@
<%= form_tag(content_change_request_url, :method => :post) do %>
<%= render "support/author" %>
- <fieldset>
- <label for="inside_government">Does this affect Inside Government?</label>
- <select id="inside_government" name="inside_government">
- <option selected="selected" value="no">No</option>
- <option value="yes">Yes</option>
- </select>
- </fieldset>
+ <%= render "support/inside_government" %>
<fieldset>
<legend>URL(s) affected</legend>
@@ -2,18 +2,18 @@
<%= content_for :header, "Create a new user account" %>
<div class="well">
- <%= form_tag('/create-user', :method => :post) do %>
- <%= render "author" %>
+ <%= form_tag(create_new_user_request_url, :method => :post) do %>
+ <%= render "support/author" %>
<header class="section-header">User details</header>
<label for="user_name">Name (required)</label>
- <input id="user_name" name="user_name" class="span6" type="text" required aria-required="true" <%= render "assignvalue", {:param => @formdata[:user_name]} %>>
- <%= render "errors", {errors: @errors, key: "User name"} %>
+ <input id="user_name" name="user_name" class="span6" type="text" required aria-required="true" <%= render "support/assignvalue", {:param => @formdata[:user_name]} %>>
+ <%= render "support/errors", {errors: @errors, key: "User name"} %>
<label for="email">Email (required)</label>
- <input id="email" name="user_email" class="span6" type="email" required aria-required="true" <%= render "assignvalue", {:param => @formdata[:user_email]} %>>
- <%= render "errors", {errors: @errors, key: "User email"} %>
+ <input id="email" name="user_email" class="span6" type="email" required aria-required="true" <%= render "support/assignvalue", {:param => @formdata[:user_email]} %>>
+ <%= render "support/errors", {errors: @errors, key: "User email"} %>
<fieldset>
<div class="comments">
@@ -37,8 +37,8 @@
</ul>
<ul class="nav nav-list">
<li class="nav-header">User Access</li>
- <%= nav_link 'Create new user', '/create-user' %>
- <%= nav_link 'Remove user', '/remove-user' %>
+ <%= nav_link 'Create new user', new_create_new_user_request_url %>
+ <%= nav_link 'Remove user', new_remove_user_request_url %>
</ul>
<ul class="nav nav-list">
<li class="nav-header">Campaigns</li>
@@ -2,23 +2,22 @@
<%= content_for :header, "Request to remove user access" %>
<div class="well">
- <%= form_tag('/remove-user', :method => :post) do %>
-
- <%= render "author" %>
+ <%= form_tag(remove_user_request_url, :method => :post) do %>
+ <%= render "support/author" %>
<section id="user">
<header class="section-header">User details</header>
<label for="user_name">Username</label>
- <input id="user_name" name="user_name" type="text" class="span6" <%= render "assignvalue", {:param => @formdata[:user_name]} %>>
- <%= render "errors", {errors: @errors, key: "User name"} %>
+ <input id="user_name" name="user_name" type="text" class="span6" <%= render "support/assignvalue", {:param => @formdata[:user_name]} %>>
+ <%= render "support/errors", {errors: @errors, key: "User name"} %>
<label for="email">Email</label>
- <input id="email" name="user_email" type="email" class="span6" <%= render "assignvalue", {:param => @formdata[:user_email]} %>>
- <%= render "errors", {errors: @errors, key: "User email"} %>
+ <input id="email" name="user_email" type="email" class="span6" <%= render "support/assignvalue", {:param => @formdata[:user_email]} %>>
+ <%= render "support/errors", {errors: @errors, key: "User email"} %>
- <%= render "date", {:title => "Not before", :label => 'not_before', :day => @formdata[:not_before_day], :month => @formdata[:not_before_month], :year => @formdata[:not_before_year]}%>
- <%= render "errors", {errors: @errors, key: "Not before"} %>
+ <%= render "support/date", {:title => "Not before", :label => 'not_before', :day => @formdata[:not_before_day], :month => @formdata[:not_before_month], :year => @formdata[:not_before_year]}%>
+ <%= render "support/errors", {errors: @errors, key: "Not before"} %>
<div style="clear:both;"></div>
<fieldset>
@@ -0,0 +1,7 @@
+<fieldset>
+ <label for="inside_government">Does this affect Inside Government?</label>
+ <select id="inside_government" name="inside_government">
+ <option selected="selected" value="no">No</option>
+ <option value="yes">Yes</option>
+ </select>
+</fieldset>
View
@@ -1,8 +1,8 @@
Support::Application.routes.draw do
resource :content_change_request, :only => [:new, :create]
+ resource :create_new_user_request, :only => [:new, :create]
+ resource :remove_user_request, :only => [:new, :create]
- match "create-user" => "support#create_user"
- match "remove-user" => "support#remove_user"
match "campaign" => "support#campaign"
match "general" => "support#general"
match "publish-tool" => "support#publish_tool"
View
No changes.
@@ -1,5 +1,4 @@
-require 'ostruct'
-require_relative "../test_helper"
+require "test_helper"
class ContentChangeRequestsControllerTest < ActionController::TestCase
include ZenDeskOrganisationListHelper
@@ -0,0 +1,47 @@
+require "test_helper"
+
+class CreateNewUserRequestsControllerTest < ActionController::TestCase
+ include ZenDeskOrganisationListHelper
+ include TestData
+
+ setup do
+ login_as_stub_user
+ @zendesk_api = ZenDeskAPIClientDouble.new
+ ZendeskClient.stubs(:get_client).returns(@zendesk_api)
+ end
+
+ context "GET create_user" do
+ setup do
+ stub_zendesk_organisation_list
+ end
+
+ should "render the form" do
+ get :new
+ assert_select "h1", /Create a new user account/i
+ end
+
+ should "use ZenDesk to populate the organisation dropdown" do
+ get :new
+ assert_select "select#organisation_list option", "Advocate General for Scotland"
+ end
+ end
+
+ context "POST create_user" do
+ should "reject invalid requests" do
+ params = valid_create_new_user_request_params.merge("organisation" => "")
+ post :create, params
+ assert_response 200 # should actually be an error status, but let's worry about that later
+ assert_template "new"
+ assert_select ".help-block", /Organisation information is required/
+ end
+
+ should "submit it to ZenDesk" do
+ params = valid_create_new_user_request_params
+
+ post :create, params
+
+ assert_equal ['new_user'], @zendesk_api.ticket.options[:tags]
+ assert_redirected_to "/acknowledge"
+ end
+ end
+end
@@ -0,0 +1,51 @@
+require 'test_helper'
+
+class RemoveUserRequestsControllerTest < ActionController::TestCase
+ include ZenDeskOrganisationListHelper
+ include TestData
+
+ setup do
+ login_as_stub_user
+ @zendesk_api = ZenDeskAPIClientDouble.new
+ ZendeskClient.stubs(:get_client).returns(@zendesk_api)
+ end
+
+ context "new remove user request" do
+ setup do
+ stub_zendesk_organisation_list
+ end
+
+ should "render the form" do
+ get :new
+ assert_select "h1", /Remove User/i
+ end
+
+ should "use ZenDesk to populate the organisation dropdown" do
+ get :new
+ assert_select "select#organisation_list option", "Advocate General for Scotland"
+ end
+ end
+
+ context "submitted remove user request" do
+ setup do
+ stub_zendesk_organisation_list
+ end
+
+ should "reject invalid requests" do
+ params = valid_remove_user_request_params.merge("organisation" => "")
+ post :create, params
+ assert_response 200 # should actually be an error status, but let's worry about that later
+ assert_template "new"
+ assert_select ".help-block", /Organisation information is required/
+ end
+
+ should "submit it to ZenDesk" do
+ params = valid_remove_user_request_params
+
+ post :create, params
+
+ assert_equal ['remove_user'], @zendesk_api.ticket.options[:tags]
+ assert_redirected_to "/acknowledge"
+ end
+ end
+end
@@ -1,4 +1,4 @@
-require_relative "../test_helper"
+require "test_helper"
class SupportControllerTest < ActionController::TestCase
include ZenDeskOrganisationListHelper
@@ -17,80 +17,6 @@ class SupportControllerTest < ActionController::TestCase
end
end
- context "GET create_user" do
- setup do
- stub_zendesk_organisation_list
- end
-
- should "render the form" do
- get :create_user
- assert_select "h1", /Create a new user account/i
- end
-
- should "use ZenDesk to populate the organisation dropdown" do
- get :create_user
- assert_select "select#organisation_list option", "Advocate General for Scotland"
- end
- end
-
- context "POST create_user" do
- should "reject invalid requests" do
- params = valid_create_new_user_request_params.merge("organisation" => "")
- post :create_user, params
- assert_response 200 # should actually be an error status, but let's worry about that later
- assert_template "useraccess/user"
- assert_select ".help-block", /Organisation information is required/
- end
-
- should "submit it to ZenDesk" do
- params = valid_create_new_user_request_params
-
- post :create_user, params
-
- assert_equal ['new_user'], @zendesk_api.ticket.options[:tags]
- assert_redirected_to "/acknowledge"
- end
- end
-
- context "GET remove_user" do
- setup do
- stub_zendesk_organisation_list
- end
-
- should "render the form" do
- get :remove_user
- assert_select "h1", /Remove User/i
- end
-
- should "use ZenDesk to populate the organisation dropdown" do
- get :remove_user
- assert_select "select#organisation_list option", "Advocate General for Scotland"
- end
- end
-
- context "POST remove_user" do
- setup do
- stub_zendesk_organisation_list
- end
-
- should "reject invalid requests" do
- params = valid_remove_user_request_params.merge("organisation" => "")
- post :remove_user, params
- assert_response 200 # should actually be an error status, but let's worry about that later
- assert_template "useraccess/user"
- assert_select ".help-block", /Organisation information is required/
- end
-
- should "submit it to ZenDesk" do
- params = valid_remove_user_request_params
-
- post :remove_user, params
-
- assert_equal ['remove_user'], @zendesk_api.ticket.options[:tags]
- assert_redirected_to "/acknowledge"
- end
- end
-
context "GET campaign" do
setup do
stub_zendesk_organisation_list
View
@@ -5,6 +5,7 @@
require 'mocha_standalone'
require 'webmock/minitest'
+require 'ostruct'
require_relative 'test_data'
class ActiveSupport::TestCase

0 comments on commit 7848f12

Please sign in to comment.