g5_authenticatable 0.9.1.pre.2 → 1.0.0.pre.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.ruby-version +1 -1
- data/.travis.yml +23 -9
- data/Appraisals +17 -0
- data/CHANGELOG.md +14 -0
- data/Gemfile +11 -14
- data/README.md +40 -13
- data/app/controllers/concerns/g5_authenticatable/authorization.rb +4 -1
- data/app/controllers/g5_authenticatable/application_controller.rb +3 -0
- data/app/controllers/g5_authenticatable/error_controller.rb +3 -2
- data/app/controllers/g5_authenticatable/failure_app.rb +35 -0
- data/app/controllers/g5_authenticatable/sessions_controller.rb +7 -3
- data/app/helpers/g5_authenticatable/application_helper.rb +3 -0
- data/app/models/g5_authenticatable/role.rb +5 -2
- data/app/models/g5_authenticatable/user.rb +12 -5
- data/app/policies/g5_authenticatable/base_policy.rb +75 -58
- data/app/policies/g5_updatable/client_policy.rb +5 -5
- data/app/policies/g5_updatable/location_policy.rb +6 -5
- data/app/policies/g5_updatable/selectable_client_policy.rb +6 -7
- data/app/services/g5_authenticatable/impersonate_sessionable.rb +12 -7
- data/config/initializers/devise.rb +4 -0
- data/config/initializers/impersonate_strategy.rb +5 -2
- data/config/initializers/rolify.rb +2 -0
- data/config/routes.rb +3 -1
- data/g5_authenticatable.gemspec +11 -7
- data/gemfiles/rails_4.1.gemfile +28 -0
- data/gemfiles/rails_4.2.gemfile +28 -0
- data/gemfiles/rails_5.0.gemfile +28 -0
- data/gemfiles/rails_5.1.gemfile +28 -0
- data/lib/g5_authenticatable.rb +3 -1
- data/lib/g5_authenticatable/engine.rb +5 -2
- data/lib/g5_authenticatable/rspec.rb +2 -0
- data/lib/g5_authenticatable/test/controller_helpers.rb +14 -9
- data/lib/g5_authenticatable/test/env_helpers.rb +3 -0
- data/lib/g5_authenticatable/test/factories/client_users.rb +45 -0
- data/lib/g5_authenticatable/test/factories/global_users.rb +43 -0
- data/lib/g5_authenticatable/test/factories/location_users.rb +45 -0
- data/lib/g5_authenticatable/test/factories/roles.rb +63 -0
- data/lib/g5_authenticatable/test/factory.rb +7 -59
- data/lib/g5_authenticatable/test/feature_helpers.rb +31 -17
- data/lib/g5_authenticatable/test/request_helpers.rb +5 -1
- data/lib/g5_authenticatable/test/token_validation_helpers.rb +15 -10
- data/lib/g5_authenticatable/version.rb +3 -1
- data/lib/generators/g5_authenticatable/install/install_generator.rb +49 -37
- data/lib/generators/g5_authenticatable/install/templates/application_policy.rb +2 -0
- data/lib/generators/g5_authenticatable/install/templates/initializer.rb +2 -0
- data/lib/generators/g5_authenticatable/install/templates/migrate/add_g5_authenticatable_users_contact_info.rb +3 -1
- data/lib/generators/g5_authenticatable/install/templates/migrate/create_g5_authenticatable_roles.rb +3 -1
- data/lib/generators/g5_authenticatable/install/templates/migrate/create_g5_authenticatable_users.rb +3 -1
- data/lib/tasks/g5_authenticatable/purge_users.rake +2 -0
- data/spec/config/application_spec.rb +7 -4
- data/spec/controllers/application_controller_spec.rb +10 -5
- data/spec/controllers/concerns/g5_authenticatable/{authorization.rb → authorization_spec.rb} +11 -6
- data/spec/dummy/app/controllers/home_controller.rb +5 -5
- data/spec/dummy/app/controllers/rails_api/secure_resources_controller.rb +6 -4
- data/spec/dummy/app/models/post.rb +1 -1
- data/spec/dummy/config/environments/test.rb +25 -4
- data/spec/dummy/config/initializers/rails_compatibility.rb +10 -0
- data/spec/dummy/db/migrate/20140206070137_create_g5_authenticatable_users.rb +3 -1
- data/spec/dummy/db/migrate/20150428182339_add_g5_authenticatable_users_contact_info.rb +3 -1
- data/spec/dummy/db/migrate/20150429212919_create_g5_authenticatable_roles.rb +2 -1
- data/spec/dummy/db/migrate/20150509061150_create_posts.rb +3 -1
- data/spec/dummy/db/migrate/20150603224032_create_g5_updatable_clients_and_locations.g5_updatable.rb +3 -1
- data/spec/dummy/db/migrate/20150603224033_create_integration_setting.g5_updatable.rb +3 -1
- data/spec/dummy/db/migrate/20150603224034_remove_integration_setting.g5_updatable.rb +3 -1
- data/spec/dummy/db/migrate/20150603224035_add_name_to_clients_and_locations.g5_updatable.rb +3 -1
- data/spec/dummy/db/migrate/20150603224036_update_names.g5_updatable.rb +3 -1
- data/spec/dummy/db/migrate/20170613201430_add_latitude_and_longitude_to_location.g5_updatable.rb +7 -0
- data/spec/dummy/db/migrate/20170613201431_copy_lat_long_props_to_lat_long_columns.g5_updatable.rb +20 -0
- data/spec/dummy/db/migrate/20170613201432_add_latitude_longitude_indexes_to_location.g5_updatable.rb +7 -0
- data/spec/dummy/db/migrate/{20161122070749_add_amenities.rb → 20170613201433_add_amenities.g5_updatable.rb} +2 -1
- data/spec/dummy/db/migrate/{20161209070749_add_client_urn_to_locations.rb → 20170613201434_add_client_urn_to_locations.g5_updatable.rb} +2 -1
- data/spec/dummy/db/migrate/20170613201435_add_points_of_interest.g5_updatable.rb +21 -0
- data/spec/dummy/db/migrate/20170613201436_add_unique_urn_indexes.g5_updatable.rb +11 -0
- data/spec/dummy/db/schema.rb +73 -61
- data/spec/factories/post.rb +2 -0
- data/spec/features/auth_error_path_spec.rb +3 -3
- data/spec/features/default_role_authorization_spec.rb +8 -4
- data/spec/features/sign_in_spec.rb +23 -13
- data/spec/features/token_validation_spec.rb +4 -2
- data/spec/g5_authenticatable/version_spec.rb +3 -1
- data/spec/lib/generators/g5_authenticatable/install_generator_spec.rb +73 -28
- data/spec/models/g5_authenticatable/role_spec.rb +8 -4
- data/spec/models/g5_authenticatable/user_spec.rb +119 -84
- data/spec/models/post_spec.rb +4 -2
- data/spec/policies/application_policy_spec.rb +80 -47
- data/spec/policies/client_policy_spec.rb +8 -5
- data/spec/policies/location_policy_spec.rb +21 -8
- data/spec/policies/selectable_client_policy_spec.rb +26 -15
- data/spec/rails_helper.rb +41 -0
- data/spec/requests/default_role_authorization_spec.rb +18 -14
- data/spec/requests/grape_api_spec.rb +7 -5
- data/spec/requests/rails_api_spec.rb +11 -9
- data/spec/requests/sign_out_spec.rb +10 -6
- data/spec/requests/token_validation_spec.rb +9 -5
- data/spec/routing/auth_error_routing_spec.rb +7 -6
- data/spec/routing/sign_out_routing_spec.rb +7 -5
- data/spec/services/g5_authenticatable/impersonate_sessionable_spec.rb +41 -18
- data/spec/spec_helper.rb +78 -45
- data/spec/support/devise.rb +3 -1
- data/spec/support/safe_request_helpers.rb +36 -0
- data/spec/support/shared_contexts/rake.rb +10 -4
- data/spec/support/shared_examples/super_admin_authorizer.rb +3 -1
- data/spec/tasks/purge_users_spec.rb +3 -1
- metadata +75 -39
- data/spec/controllers/.gitkeep +0 -0
data/spec/dummy/db/migrate/20150603224032_create_g5_updatable_clients_and_locations.g5_updatable.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# This migration comes from g5_updatable (originally 20140709222005)
|
2
|
-
class CreateG5UpdatableClientsAndLocations < ActiveRecord::Migration
|
4
|
+
class CreateG5UpdatableClientsAndLocations < ActiveRecord::Migration[4.2]
|
3
5
|
def change
|
4
6
|
create_table :g5_updatable_clients do |t|
|
5
7
|
t.string :uid
|
@@ -1,5 +1,7 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# This migration comes from g5_updatable (originally 20141030211945)
|
2
|
-
class CreateIntegrationSetting < ActiveRecord::Migration
|
4
|
+
class CreateIntegrationSetting < ActiveRecord::Migration[4.2]
|
3
5
|
def change
|
4
6
|
create_table :g5_updatable_integration_settings do |t|
|
5
7
|
t.string :uid
|
@@ -1,5 +1,7 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# This migration comes from g5_updatable (originally 20141122211945)
|
2
|
-
class RemoveIntegrationSetting < ActiveRecord::Migration
|
4
|
+
class RemoveIntegrationSetting < ActiveRecord::Migration[4.2]
|
3
5
|
def change
|
4
6
|
drop_table :g5_updatable_integration_settings
|
5
7
|
end
|
@@ -1,5 +1,7 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# This migration comes from g5_updatable (originally 20141211211945)
|
2
|
-
class AddNameToClientsAndLocations < ActiveRecord::Migration
|
4
|
+
class AddNameToClientsAndLocations < ActiveRecord::Migration[4.2]
|
3
5
|
def change
|
4
6
|
add_column :g5_updatable_clients, :name, :string
|
5
7
|
add_index :g5_updatable_clients, :name
|
@@ -1,5 +1,7 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# This migration comes from g5_updatable (originally 20141211711945)
|
2
|
-
class UpdateNames < ActiveRecord::Migration
|
4
|
+
class UpdateNames < ActiveRecord::Migration[4.2]
|
3
5
|
def change
|
4
6
|
G5Updatable::Client.all.each do |client|
|
5
7
|
client.update_attributes(name: client.properties['name'])
|
data/spec/dummy/db/migrate/20170613201430_add_latitude_and_longitude_to_location.g5_updatable.rb
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
# This migration comes from g5_updatable (originally 20151103043916)
|
2
|
+
class AddLatitudeAndLongitudeToLocation < ActiveRecord::Migration[4.2]
|
3
|
+
def change
|
4
|
+
add_column :g5_updatable_locations, :latitude, :float
|
5
|
+
add_column :g5_updatable_locations, :longitude, :float
|
6
|
+
end
|
7
|
+
end
|
data/spec/dummy/db/migrate/20170613201431_copy_lat_long_props_to_lat_long_columns.g5_updatable.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# This migration comes from g5_updatable (originally 20151103050229)
|
2
|
+
class CopyLatLongPropsToLatLongColumns < ActiveRecord::Migration[4.2]
|
3
|
+
def up
|
4
|
+
G5Updatable::Location.all.each do |location|
|
5
|
+
location.latitude = location.properties['latitude']
|
6
|
+
location.longitude = location.properties['longitude']
|
7
|
+
location.save
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def down
|
12
|
+
G5Updatable::Location.all.each do |location|
|
13
|
+
location.properties['latitude'] = location.latitude
|
14
|
+
location.proper['longitude'] = location.longitude
|
15
|
+
location.latitude = nil
|
16
|
+
location.longitude = nil
|
17
|
+
location.save
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -1,4 +1,5 @@
|
|
1
|
-
|
1
|
+
# This migration comes from g5_updatable (originally 20161209070749)
|
2
|
+
class AddClientUrnToLocations < ActiveRecord::Migration[4.2]
|
2
3
|
def change
|
3
4
|
add_column :g5_updatable_locations, :client_urn, :string
|
4
5
|
add_index :g5_updatable_locations, :client_urn
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# This migration comes from g5_updatable (originally 20170422000000)
|
2
|
+
class AddPointsOfInterest < ActiveRecord::Migration[4.2]
|
3
|
+
def change
|
4
|
+
create_table :g5_updatable_points_of_interest do |t|
|
5
|
+
t.belongs_to :g5_updatable_location
|
6
|
+
t.string "place_id"
|
7
|
+
t.string "name"
|
8
|
+
t.string "address"
|
9
|
+
t.string "city"
|
10
|
+
t.string "state"
|
11
|
+
t.string "postal_code"
|
12
|
+
t.string "location_type"
|
13
|
+
t.float "latitude"
|
14
|
+
t.float "longitude"
|
15
|
+
t.timestamps
|
16
|
+
end
|
17
|
+
|
18
|
+
add_index :g5_updatable_points_of_interest, :g5_updatable_location_id, name: 'index_g5_updatable_poi_location_id'
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# This migration comes from g5_updatable (originally 20170507000000)
|
2
|
+
class AddUniqueUrnIndexes < ActiveRecord::Migration[4.2]
|
3
|
+
# indexes were not made to enforce uniqueness
|
4
|
+
def change
|
5
|
+
remove_index :g5_updatable_clients, :urn
|
6
|
+
add_index :g5_updatable_clients, :urn, unique: true
|
7
|
+
remove_index :g5_updatable_locations, :urn
|
8
|
+
add_index :g5_updatable_locations, :urn, unique: true
|
9
|
+
|
10
|
+
end
|
11
|
+
end
|
data/spec/dummy/db/schema.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
# encoding: UTF-8
|
2
1
|
# This file is auto-generated from the current state of the database. Instead
|
3
2
|
# of editing this file, please use the migrations feature of Active Record to
|
4
3
|
# incrementally modify your database, and then regenerate this schema definition.
|
@@ -11,104 +10,117 @@
|
|
11
10
|
#
|
12
11
|
# It's strongly recommended that you check this file into your version control system.
|
13
12
|
|
14
|
-
ActiveRecord::Schema.define(version:
|
13
|
+
ActiveRecord::Schema.define(version: 20170613201436) do
|
15
14
|
|
16
15
|
# These are extensions that must be enabled in order to support this database
|
17
16
|
enable_extension "plpgsql"
|
18
17
|
|
19
|
-
create_table "g5_authenticatable_roles", force: :cascade do |t|
|
20
|
-
t.string
|
21
|
-
t.
|
22
|
-
t.
|
18
|
+
create_table "g5_authenticatable_roles", id: :serial, force: :cascade do |t|
|
19
|
+
t.string "name"
|
20
|
+
t.string "resource_type"
|
21
|
+
t.integer "resource_id"
|
23
22
|
t.datetime "created_at"
|
24
23
|
t.datetime "updated_at"
|
24
|
+
t.index ["name", "resource_type", "resource_id"], name: "index_g5_authenticatable_roles_on_name_and_resource"
|
25
|
+
t.index ["name"], name: "index_g5_authenticatable_roles_on_name"
|
25
26
|
end
|
26
27
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
t.string
|
32
|
-
t.
|
33
|
-
t.string "uid", null: false
|
34
|
-
t.string "g5_access_token"
|
35
|
-
t.integer "sign_in_count", default: 0, null: false
|
28
|
+
create_table "g5_authenticatable_users", id: :serial, force: :cascade do |t|
|
29
|
+
t.string "email", default: "", null: false
|
30
|
+
t.string "provider", default: "g5", null: false
|
31
|
+
t.string "uid", null: false
|
32
|
+
t.string "g5_access_token"
|
33
|
+
t.integer "sign_in_count", default: 0, null: false
|
36
34
|
t.datetime "current_sign_in_at"
|
37
35
|
t.datetime "last_sign_in_at"
|
38
|
-
t.string
|
39
|
-
t.string
|
36
|
+
t.string "current_sign_in_ip"
|
37
|
+
t.string "last_sign_in_ip"
|
40
38
|
t.datetime "created_at"
|
41
39
|
t.datetime "updated_at"
|
42
|
-
t.string
|
43
|
-
t.string
|
44
|
-
t.string
|
45
|
-
t.string
|
46
|
-
t.string
|
40
|
+
t.string "first_name"
|
41
|
+
t.string "last_name"
|
42
|
+
t.string "phone_number"
|
43
|
+
t.string "title"
|
44
|
+
t.string "organization_name"
|
45
|
+
t.index ["email"], name: "index_g5_authenticatable_users_on_email", unique: true
|
46
|
+
t.index ["provider", "uid"], name: "index_g5_authenticatable_users_on_provider_and_uid", unique: true
|
47
47
|
end
|
48
48
|
|
49
|
-
add_index "g5_authenticatable_users", ["email"], name: "index_g5_authenticatable_users_on_email", unique: true, using: :btree
|
50
|
-
add_index "g5_authenticatable_users", ["provider", "uid"], name: "index_g5_authenticatable_users_on_provider_and_uid", unique: true, using: :btree
|
51
|
-
|
52
49
|
create_table "g5_authenticatable_users_roles", id: false, force: :cascade do |t|
|
53
50
|
t.integer "user_id"
|
54
51
|
t.integer "role_id"
|
52
|
+
t.index ["user_id", "role_id"], name: "index_g5_authenticatable_users_roles_on_user_id_and_role_id"
|
55
53
|
end
|
56
54
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
t.
|
61
|
-
t.string "urn"
|
62
|
-
t.json "properties"
|
55
|
+
create_table "g5_updatable_clients", id: :serial, force: :cascade do |t|
|
56
|
+
t.string "uid"
|
57
|
+
t.string "urn"
|
58
|
+
t.json "properties"
|
63
59
|
t.datetime "created_at"
|
64
60
|
t.datetime "updated_at"
|
65
|
-
t.string
|
61
|
+
t.string "name"
|
62
|
+
t.index ["name"], name: "index_g5_updatable_clients_on_name"
|
63
|
+
t.index ["uid"], name: "index_g5_updatable_clients_on_uid"
|
64
|
+
t.index ["urn"], name: "index_g5_updatable_clients_on_urn", unique: true
|
66
65
|
end
|
67
66
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
create_table "g5_updatable_hub_amenities", force: :cascade do |t|
|
73
|
-
t.integer "external_id"
|
74
|
-
t.string "name"
|
75
|
-
t.string "icon"
|
67
|
+
create_table "g5_updatable_hub_amenities", id: :serial, force: :cascade do |t|
|
68
|
+
t.integer "external_id"
|
69
|
+
t.string "name"
|
70
|
+
t.string "icon"
|
76
71
|
t.datetime "external_updated_at"
|
77
72
|
t.datetime "external_created_at"
|
78
73
|
t.datetime "created_at"
|
79
74
|
t.datetime "updated_at"
|
75
|
+
t.index ["external_id"], name: "index_g5_updatable_hub_amenities_on_external_id", unique: true
|
80
76
|
end
|
81
77
|
|
82
|
-
|
83
|
-
|
84
|
-
create_table "g5_updatable_hub_amenities_locations", force: :cascade do |t|
|
78
|
+
create_table "g5_updatable_hub_amenities_locations", id: :serial, force: :cascade do |t|
|
85
79
|
t.integer "g5_updatable_hub_amenity_id"
|
86
80
|
t.integer "g5_updatable_location_id"
|
81
|
+
t.index ["g5_updatable_hub_amenity_id"], name: "updatable_amenities_loc_amen_id"
|
82
|
+
t.index ["g5_updatable_location_id"], name: "updatable_amenities_loc_loc_id"
|
87
83
|
end
|
88
84
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
t.
|
94
|
-
t.string "urn"
|
95
|
-
t.string "client_uid"
|
96
|
-
t.json "properties"
|
85
|
+
create_table "g5_updatable_locations", id: :serial, force: :cascade do |t|
|
86
|
+
t.string "uid"
|
87
|
+
t.string "urn"
|
88
|
+
t.string "client_uid"
|
89
|
+
t.json "properties"
|
97
90
|
t.datetime "created_at"
|
98
91
|
t.datetime "updated_at"
|
99
|
-
t.string
|
100
|
-
t.
|
101
|
-
t.
|
92
|
+
t.string "name"
|
93
|
+
t.float "latitude"
|
94
|
+
t.float "longitude"
|
95
|
+
t.string "flat_amenity_names"
|
96
|
+
t.string "client_urn"
|
97
|
+
t.index ["client_urn"], name: "index_g5_updatable_locations_on_client_urn"
|
98
|
+
t.index ["latitude"], name: "index_g5_updatable_locations_on_latitude"
|
99
|
+
t.index ["longitude"], name: "index_g5_updatable_locations_on_longitude"
|
100
|
+
t.index ["name"], name: "index_g5_updatable_locations_on_name"
|
101
|
+
t.index ["uid"], name: "index_g5_updatable_locations_on_uid"
|
102
|
+
t.index ["urn"], name: "index_g5_updatable_locations_on_urn", unique: true
|
102
103
|
end
|
103
104
|
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
105
|
+
create_table "g5_updatable_points_of_interest", id: :serial, force: :cascade do |t|
|
106
|
+
t.integer "g5_updatable_location_id"
|
107
|
+
t.string "place_id"
|
108
|
+
t.string "name"
|
109
|
+
t.string "address"
|
110
|
+
t.string "city"
|
111
|
+
t.string "state"
|
112
|
+
t.string "postal_code"
|
113
|
+
t.string "location_type"
|
114
|
+
t.float "latitude"
|
115
|
+
t.float "longitude"
|
116
|
+
t.datetime "created_at"
|
117
|
+
t.datetime "updated_at"
|
118
|
+
t.index ["g5_updatable_location_id"], name: "index_g5_updatable_poi_location_id"
|
119
|
+
end
|
108
120
|
|
109
|
-
create_table "posts", force: :cascade do |t|
|
110
|
-
t.integer
|
111
|
-
t.string
|
121
|
+
create_table "posts", id: :serial, force: :cascade do |t|
|
122
|
+
t.integer "author_id"
|
123
|
+
t.string "content"
|
112
124
|
t.datetime "created_at", null: false
|
113
125
|
t.datetime "updated_at", null: false
|
114
126
|
end
|
data/spec/factories/post.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
require 'rails_helper'
|
4
|
+
|
5
|
+
RSpec.describe 'Default role-based authorization UI' do
|
4
6
|
describe 'Posts index' do
|
5
7
|
let(:visit_posts_index) { visit_path_and_login_with(posts_path, user) }
|
6
8
|
|
@@ -148,7 +150,9 @@ describe 'Default role-based authorization UI' do
|
|
148
150
|
end
|
149
151
|
|
150
152
|
describe 'Edit post' do
|
151
|
-
subject(:edit_post)
|
153
|
+
subject(:edit_post) do
|
154
|
+
visit_path_and_login_with(edit_post_path(post.id), user)
|
155
|
+
end
|
152
156
|
before { edit_post }
|
153
157
|
|
154
158
|
let(:post) { FactoryGirl.create(:post, author: user) }
|
@@ -222,7 +226,7 @@ describe 'Default role-based authorization UI' do
|
|
222
226
|
describe 'Delete post' do
|
223
227
|
subject(:delete_post) { click_link 'Destroy' }
|
224
228
|
|
225
|
-
let!(:post) { FactoryGirl.create(:post, author: user) }
|
229
|
+
let!(:post) { FactoryGirl.create(:post, author: user) }
|
226
230
|
let(:user) { FactoryGirl.create(:g5_authenticatable_super_admin) }
|
227
231
|
|
228
232
|
before { visit_path_and_login_with(posts_path, user) }
|
@@ -1,7 +1,9 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
require 'rails_helper'
|
4
|
+
|
5
|
+
RSpec.describe 'Signing in' do
|
6
|
+
let(:user) { FactoryGirl.create(:g5_authenticatable_viewer) }
|
5
7
|
|
6
8
|
context 'from a login link' do
|
7
9
|
subject(:login) { click_link 'Login' }
|
@@ -10,7 +12,7 @@ describe 'Signing in' do
|
|
10
12
|
|
11
13
|
context 'when user exists locally' do
|
12
14
|
before do
|
13
|
-
OmniAuth.config.mock_auth[:g5] = OmniAuth::AuthHash.new(
|
15
|
+
OmniAuth.config.mock_auth[:g5] = OmniAuth::AuthHash.new(
|
14
16
|
uid: user.uid,
|
15
17
|
provider: user.provider,
|
16
18
|
info: {
|
@@ -28,10 +30,10 @@ describe 'Signing in' do
|
|
28
30
|
extra: {
|
29
31
|
title: updated_title,
|
30
32
|
organization_name: updated_organization_name,
|
31
|
-
roles: [{name: updated_role.name, type: 'GLOBAL', urn: nil}],
|
33
|
+
roles: [{ name: updated_role.name, type: 'GLOBAL', urn: nil }],
|
32
34
|
raw_info: {}
|
33
35
|
}
|
34
|
-
|
36
|
+
)
|
35
37
|
end
|
36
38
|
|
37
39
|
let(:updated_first_name) { "Updated #{user.first_name}" }
|
@@ -40,7 +42,9 @@ describe 'Signing in' do
|
|
40
42
|
let(:updated_title) { "Updated #{user.title}" }
|
41
43
|
let(:updated_organization_name) { "Updated #{user.organization_name}" }
|
42
44
|
let(:updated_access_token) { "updated-#{user.g5_access_token}-123" }
|
43
|
-
let(:updated_role)
|
45
|
+
let(:updated_role) do
|
46
|
+
FactoryGirl.create(:g5_authenticatable_super_admin_role)
|
47
|
+
end
|
44
48
|
|
45
49
|
it 'should sign in the user successfully' do
|
46
50
|
login
|
@@ -105,12 +109,14 @@ describe 'Signing in' do
|
|
105
109
|
|
106
110
|
context 'when user does not exist locally' do
|
107
111
|
before do
|
108
|
-
|
112
|
+
full_name = [user_attributes[:first_name],
|
113
|
+
user_attributes[:last_name]].join(' ')
|
114
|
+
OmniAuth.config.mock_auth[:g5] = OmniAuth::AuthHash.new(
|
109
115
|
uid: user_attributes[:uid],
|
110
116
|
provider: user_attributes[:provider],
|
111
117
|
info: {
|
112
118
|
email: user_attributes[:email],
|
113
|
-
name:
|
119
|
+
name: full_name,
|
114
120
|
first_name: user_attributes[:first_name],
|
115
121
|
last_name: user_attributes[:last_name],
|
116
122
|
phone: user_attributes[:phone_number]
|
@@ -123,14 +129,18 @@ describe 'Signing in' do
|
|
123
129
|
extra: {
|
124
130
|
title: user_attributes[:title],
|
125
131
|
organization_name: user_attributes[:organization_name],
|
126
|
-
roles: [{name: role_attributes[:name], type: 'GLOBAL', urn: nil}],
|
132
|
+
roles: [{ name: role_attributes[:name], type: 'GLOBAL', urn: nil }],
|
127
133
|
raw_info: {}
|
128
134
|
}
|
129
|
-
|
135
|
+
)
|
130
136
|
end
|
131
137
|
|
132
|
-
let(:user_attributes)
|
133
|
-
|
138
|
+
let(:user_attributes) do
|
139
|
+
FactoryGirl.attributes_for(:g5_authenticatable_user)
|
140
|
+
end
|
141
|
+
let(:role_attributes) do
|
142
|
+
FactoryGirl.attributes_for(:g5_authenticatable_editor_role)
|
143
|
+
end
|
134
144
|
|
135
145
|
it 'should sign in the user successfully' do
|
136
146
|
login
|