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.
Files changed (107) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.ruby-version +1 -1
  4. data/.travis.yml +23 -9
  5. data/Appraisals +17 -0
  6. data/CHANGELOG.md +14 -0
  7. data/Gemfile +11 -14
  8. data/README.md +40 -13
  9. data/app/controllers/concerns/g5_authenticatable/authorization.rb +4 -1
  10. data/app/controllers/g5_authenticatable/application_controller.rb +3 -0
  11. data/app/controllers/g5_authenticatable/error_controller.rb +3 -2
  12. data/app/controllers/g5_authenticatable/failure_app.rb +35 -0
  13. data/app/controllers/g5_authenticatable/sessions_controller.rb +7 -3
  14. data/app/helpers/g5_authenticatable/application_helper.rb +3 -0
  15. data/app/models/g5_authenticatable/role.rb +5 -2
  16. data/app/models/g5_authenticatable/user.rb +12 -5
  17. data/app/policies/g5_authenticatable/base_policy.rb +75 -58
  18. data/app/policies/g5_updatable/client_policy.rb +5 -5
  19. data/app/policies/g5_updatable/location_policy.rb +6 -5
  20. data/app/policies/g5_updatable/selectable_client_policy.rb +6 -7
  21. data/app/services/g5_authenticatable/impersonate_sessionable.rb +12 -7
  22. data/config/initializers/devise.rb +4 -0
  23. data/config/initializers/impersonate_strategy.rb +5 -2
  24. data/config/initializers/rolify.rb +2 -0
  25. data/config/routes.rb +3 -1
  26. data/g5_authenticatable.gemspec +11 -7
  27. data/gemfiles/rails_4.1.gemfile +28 -0
  28. data/gemfiles/rails_4.2.gemfile +28 -0
  29. data/gemfiles/rails_5.0.gemfile +28 -0
  30. data/gemfiles/rails_5.1.gemfile +28 -0
  31. data/lib/g5_authenticatable.rb +3 -1
  32. data/lib/g5_authenticatable/engine.rb +5 -2
  33. data/lib/g5_authenticatable/rspec.rb +2 -0
  34. data/lib/g5_authenticatable/test/controller_helpers.rb +14 -9
  35. data/lib/g5_authenticatable/test/env_helpers.rb +3 -0
  36. data/lib/g5_authenticatable/test/factories/client_users.rb +45 -0
  37. data/lib/g5_authenticatable/test/factories/global_users.rb +43 -0
  38. data/lib/g5_authenticatable/test/factories/location_users.rb +45 -0
  39. data/lib/g5_authenticatable/test/factories/roles.rb +63 -0
  40. data/lib/g5_authenticatable/test/factory.rb +7 -59
  41. data/lib/g5_authenticatable/test/feature_helpers.rb +31 -17
  42. data/lib/g5_authenticatable/test/request_helpers.rb +5 -1
  43. data/lib/g5_authenticatable/test/token_validation_helpers.rb +15 -10
  44. data/lib/g5_authenticatable/version.rb +3 -1
  45. data/lib/generators/g5_authenticatable/install/install_generator.rb +49 -37
  46. data/lib/generators/g5_authenticatable/install/templates/application_policy.rb +2 -0
  47. data/lib/generators/g5_authenticatable/install/templates/initializer.rb +2 -0
  48. data/lib/generators/g5_authenticatable/install/templates/migrate/add_g5_authenticatable_users_contact_info.rb +3 -1
  49. data/lib/generators/g5_authenticatable/install/templates/migrate/create_g5_authenticatable_roles.rb +3 -1
  50. data/lib/generators/g5_authenticatable/install/templates/migrate/create_g5_authenticatable_users.rb +3 -1
  51. data/lib/tasks/g5_authenticatable/purge_users.rake +2 -0
  52. data/spec/config/application_spec.rb +7 -4
  53. data/spec/controllers/application_controller_spec.rb +10 -5
  54. data/spec/controllers/concerns/g5_authenticatable/{authorization.rb → authorization_spec.rb} +11 -6
  55. data/spec/dummy/app/controllers/home_controller.rb +5 -5
  56. data/spec/dummy/app/controllers/rails_api/secure_resources_controller.rb +6 -4
  57. data/spec/dummy/app/models/post.rb +1 -1
  58. data/spec/dummy/config/environments/test.rb +25 -4
  59. data/spec/dummy/config/initializers/rails_compatibility.rb +10 -0
  60. data/spec/dummy/db/migrate/20140206070137_create_g5_authenticatable_users.rb +3 -1
  61. data/spec/dummy/db/migrate/20150428182339_add_g5_authenticatable_users_contact_info.rb +3 -1
  62. data/spec/dummy/db/migrate/20150429212919_create_g5_authenticatable_roles.rb +2 -1
  63. data/spec/dummy/db/migrate/20150509061150_create_posts.rb +3 -1
  64. data/spec/dummy/db/migrate/20150603224032_create_g5_updatable_clients_and_locations.g5_updatable.rb +3 -1
  65. data/spec/dummy/db/migrate/20150603224033_create_integration_setting.g5_updatable.rb +3 -1
  66. data/spec/dummy/db/migrate/20150603224034_remove_integration_setting.g5_updatable.rb +3 -1
  67. data/spec/dummy/db/migrate/20150603224035_add_name_to_clients_and_locations.g5_updatable.rb +3 -1
  68. data/spec/dummy/db/migrate/20150603224036_update_names.g5_updatable.rb +3 -1
  69. data/spec/dummy/db/migrate/20170613201430_add_latitude_and_longitude_to_location.g5_updatable.rb +7 -0
  70. data/spec/dummy/db/migrate/20170613201431_copy_lat_long_props_to_lat_long_columns.g5_updatable.rb +20 -0
  71. data/spec/dummy/db/migrate/20170613201432_add_latitude_longitude_indexes_to_location.g5_updatable.rb +7 -0
  72. data/spec/dummy/db/migrate/{20161122070749_add_amenities.rb → 20170613201433_add_amenities.g5_updatable.rb} +2 -1
  73. data/spec/dummy/db/migrate/{20161209070749_add_client_urn_to_locations.rb → 20170613201434_add_client_urn_to_locations.g5_updatable.rb} +2 -1
  74. data/spec/dummy/db/migrate/20170613201435_add_points_of_interest.g5_updatable.rb +21 -0
  75. data/spec/dummy/db/migrate/20170613201436_add_unique_urn_indexes.g5_updatable.rb +11 -0
  76. data/spec/dummy/db/schema.rb +73 -61
  77. data/spec/factories/post.rb +2 -0
  78. data/spec/features/auth_error_path_spec.rb +3 -3
  79. data/spec/features/default_role_authorization_spec.rb +8 -4
  80. data/spec/features/sign_in_spec.rb +23 -13
  81. data/spec/features/token_validation_spec.rb +4 -2
  82. data/spec/g5_authenticatable/version_spec.rb +3 -1
  83. data/spec/lib/generators/g5_authenticatable/install_generator_spec.rb +73 -28
  84. data/spec/models/g5_authenticatable/role_spec.rb +8 -4
  85. data/spec/models/g5_authenticatable/user_spec.rb +119 -84
  86. data/spec/models/post_spec.rb +4 -2
  87. data/spec/policies/application_policy_spec.rb +80 -47
  88. data/spec/policies/client_policy_spec.rb +8 -5
  89. data/spec/policies/location_policy_spec.rb +21 -8
  90. data/spec/policies/selectable_client_policy_spec.rb +26 -15
  91. data/spec/rails_helper.rb +41 -0
  92. data/spec/requests/default_role_authorization_spec.rb +18 -14
  93. data/spec/requests/grape_api_spec.rb +7 -5
  94. data/spec/requests/rails_api_spec.rb +11 -9
  95. data/spec/requests/sign_out_spec.rb +10 -6
  96. data/spec/requests/token_validation_spec.rb +9 -5
  97. data/spec/routing/auth_error_routing_spec.rb +7 -6
  98. data/spec/routing/sign_out_routing_spec.rb +7 -5
  99. data/spec/services/g5_authenticatable/impersonate_sessionable_spec.rb +41 -18
  100. data/spec/spec_helper.rb +78 -45
  101. data/spec/support/devise.rb +3 -1
  102. data/spec/support/safe_request_helpers.rb +36 -0
  103. data/spec/support/shared_contexts/rake.rb +10 -4
  104. data/spec/support/shared_examples/super_admin_authorizer.rb +3 -1
  105. data/spec/tasks/purge_users_spec.rb +3 -1
  106. metadata +75 -39
  107. data/spec/controllers/.gitkeep +0 -0
@@ -1,4 +1,6 @@
1
- class CreatePosts < ActiveRecord::Migration
1
+ # frozen_string_literal: true
2
+
3
+ class CreatePosts < ActiveRecord::Migration[4.2]
2
4
  def change
3
5
  create_table :posts do |t|
4
6
  t.integer :author_id
@@ -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'])
@@ -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
@@ -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
@@ -0,0 +1,7 @@
1
+ # This migration comes from g5_updatable (originally 20151106070749)
2
+ class AddLatitudeLongitudeIndexesToLocation < ActiveRecord::Migration[4.2]
3
+ def change
4
+ add_index :g5_updatable_locations, :latitude
5
+ add_index :g5_updatable_locations, :longitude
6
+ end
7
+ end
@@ -1,4 +1,5 @@
1
- class AddAmenities < ActiveRecord::Migration
1
+ # This migration comes from g5_updatable (originally 20161122070749)
2
+ class AddAmenities < ActiveRecord::Migration[4.2]
2
3
  def change
3
4
  create_table :g5_updatable_hub_amenities do |t|
4
5
  t.integer :external_id
@@ -1,4 +1,5 @@
1
- class AddClientUrnToLocations < ActiveRecord::Migration
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
@@ -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: 20161209070749) do
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 "name"
21
- t.integer "resource_id"
22
- t.string "resource_type"
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
- add_index "g5_authenticatable_roles", ["name", "resource_type", "resource_id"], name: "index_g5_authenticatable_roles_on_name_and_resource", using: :btree
28
- add_index "g5_authenticatable_roles", ["name"], name: "index_g5_authenticatable_roles_on_name", using: :btree
29
-
30
- create_table "g5_authenticatable_users", force: :cascade do |t|
31
- t.string "email", default: "", null: false
32
- t.string "provider", default: "g5", null: false
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 "current_sign_in_ip"
39
- t.string "last_sign_in_ip"
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 "first_name"
43
- t.string "last_name"
44
- t.string "phone_number"
45
- t.string "title"
46
- t.string "organization_name"
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
- add_index "g5_authenticatable_users_roles", ["user_id", "role_id"], name: "index_g5_authenticatable_users_roles_on_user_id_and_role_id", using: :btree
58
-
59
- create_table "g5_updatable_clients", force: :cascade do |t|
60
- t.string "uid"
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 "name"
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
- add_index "g5_updatable_clients", ["name"], name: "index_g5_updatable_clients_on_name", using: :btree
69
- add_index "g5_updatable_clients", ["uid"], name: "index_g5_updatable_clients_on_uid", using: :btree
70
- add_index "g5_updatable_clients", ["urn"], name: "index_g5_updatable_clients_on_urn", using: :btree
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
- add_index "g5_updatable_hub_amenities", ["external_id"], name: "index_g5_updatable_hub_amenities_on_external_id", unique: true, using: :btree
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
- add_index "g5_updatable_hub_amenities_locations", ["g5_updatable_hub_amenity_id"], name: "updatable_amenities_loc_amen_id", using: :btree
90
- add_index "g5_updatable_hub_amenities_locations", ["g5_updatable_location_id"], name: "updatable_amenities_loc_loc_id", using: :btree
91
-
92
- create_table "g5_updatable_locations", force: :cascade do |t|
93
- t.string "uid"
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 "name"
100
- t.string "flat_amenity_names"
101
- t.string "client_urn"
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
- add_index "g5_updatable_locations", ["client_urn"], name: "index_g5_updatable_locations_on_client_urn", using: :btree
105
- add_index "g5_updatable_locations", ["name"], name: "index_g5_updatable_locations_on_name", using: :btree
106
- add_index "g5_updatable_locations", ["uid"], name: "index_g5_updatable_locations_on_uid", using: :btree
107
- add_index "g5_updatable_locations", ["urn"], name: "index_g5_updatable_locations_on_urn", using: :btree
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 "author_id"
111
- t.string "content"
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
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  FactoryGirl.define do
2
4
  factory :post do
3
5
  sequence(:content) { |n| "This is my post #{n}" }
@@ -1,9 +1,9 @@
1
- require 'spec_helper'
1
+ # frozen_string_literal: true
2
2
 
3
- describe 'error path' do
3
+ require 'rails_helper'
4
4
 
5
+ RSpec.describe 'error path' do
5
6
  context 'when there is an error at the oauth server' do
6
-
7
7
  before do
8
8
  stub_g5_invalid_credentials
9
9
  end
@@ -1,6 +1,8 @@
1
- require 'spec_helper'
1
+ # frozen_string_literal: true
2
2
 
3
- describe 'Default role-based authorization UI' do
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) { visit_path_and_login_with(edit_post_path(post.id), user) }
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
- require 'spec_helper'
1
+ # frozen_string_literal: true
2
2
 
3
- describe 'Signing in' do
4
- let(:user) { FactoryGirl.create(:g5_authenticatable_user) }
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) { FactoryGirl.create(:g5_authenticatable_super_admin_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
- OmniAuth.config.mock_auth[:g5] = OmniAuth::AuthHash.new({
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: "#{user_attributes[:first_name]} #{user_attributes[:last_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) { FactoryGirl.attributes_for(:g5_authenticatable_user) }
133
- let(:role_attributes) { FactoryGirl.attributes_for(:g5_authenticatable_editor_role) }
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