summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAzul <azul@leap.se>2014-07-04 15:40:54 +0200
committerAzul <azul@leap.se>2014-07-05 10:21:07 +0200
commit87e9ccbcdf4f99dd898b0715750092a27fff7e94 (patch)
tree9e49a287c6e95d92323253d899afa367a6f1e14e /test
parent24d108e15c38ca572d5339a39cb110d9067c0b3d (diff)
Enable unblocking handles in identities tab
There's an identities tab now for admins that will allow unblocking blocked handles. It should be easy to expand for aliases and forwards and other types of actions such as editing.
Diffstat (limited to 'test')
-rw-r--r--test/factories.rb6
-rw-r--r--test/functional/identities_controller_test.rb42
-rw-r--r--test/integration/browser/admin_test.rb24
-rw-r--r--test/support/browser_integration_test.rb2
4 files changed, 74 insertions, 0 deletions
diff --git a/test/factories.rb b/test/factories.rb
index bebda5c..a96d48c 100644
--- a/test/factories.rb
+++ b/test/factories.rb
@@ -29,6 +29,12 @@ FactoryGirl.define do
end
+ # Identities can have a lot of different purposes - alias, forward, ...
+ # So far this is a blocked handle only.
+ factory :identity do
+ address {Faker::Internet.user_name + '@' + APP_CONFIG[:domain]}
+ end
+
factory :token do
user
end
diff --git a/test/functional/identities_controller_test.rb b/test/functional/identities_controller_test.rb
new file mode 100644
index 0000000..fcdeaa2
--- /dev/null
+++ b/test/functional/identities_controller_test.rb
@@ -0,0 +1,42 @@
+require 'test_helper'
+
+class IdentitiesControllerTest < ActionController::TestCase
+
+ test "admin can list active and blocked ids" do
+ login :is_admin? => true
+ get :index
+ assert_response :success
+ assert ids = assigns(:identities)
+ end
+
+ test "non-admin can't list usernames" do
+ login
+ get :index
+ assert_access_denied
+ end
+
+ test "requires login" do
+ get :index
+ assert_login_required
+ end
+
+ test "admin can unblock username" do
+ # an identity without user_id and destination is a blocked handle
+ identity = FactoryGirl.create :identity
+ login :is_admin? => true
+ delete :destroy, id: identity.id
+ assert_response :redirect
+ assert_nil Identity.find(identity.id)
+ end
+
+ test "admin cannot remove main identity" do
+ user = FactoryGirl.create :user
+ identity = FactoryGirl.create :identity,
+ Identity.attributes_from_user(user)
+ login :is_admin? => true
+ delete :destroy, id: identity.id
+ assert_response :redirect
+ assert_equal identity, Identity.find(identity.id)
+ end
+
+end
diff --git a/test/integration/browser/admin_test.rb b/test/integration/browser/admin_test.rb
new file mode 100644
index 0000000..2d3f988
--- /dev/null
+++ b/test/integration/browser/admin_test.rb
@@ -0,0 +1,24 @@
+require 'test_helper'
+
+class AdminTest < BrowserIntegrationTest
+
+ test "clear blocked handle" do
+ id = FactoryGirl.create :identity
+ submit_signup(id.login)
+ assert page.has_content?('has already been taken')
+ login
+ with_config admins: [@user.login] do
+ visit '/'
+ click_on "Usernames"
+ within "##{dom_id(id)}" do
+ assert page.has_content? id.login
+ click_on "Destroy"
+ end
+ assert page.has_no_content? id.login
+ click_on 'Log Out'
+ end
+ submit_signup(id.login)
+ assert page.has_content?("Welcome #{id.login}")
+ click_on 'Log Out'
+ end
+end
diff --git a/test/support/browser_integration_test.rb b/test/support/browser_integration_test.rb
index 4fec59f..c01b8a1 100644
--- a/test/support/browser_integration_test.rb
+++ b/test/support/browser_integration_test.rb
@@ -5,6 +5,8 @@
#
class BrowserIntegrationTest < ActionDispatch::IntegrationTest
+ # let's use dom_id inorder to identify sections
+ include ActionController::RecordIdentifier
CONFIG_RU = (Rails.root + 'config.ru').to_s
OUTER_APP = Rack::Builder.parse_file(CONFIG_RU).first