punk 0.3.2 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/test.yml +1 -1
- data/.rdoc_options +0 -1
- data/.rubocop.yml +1091 -93
- data/.standard.yml +2 -0
- data/Gemfile +60 -61
- data/Gemfile.lock +64 -59
- data/README.md +7 -3
- data/Rakefile +9 -7
- data/VERSION +1 -1
- data/app/migrations/001_lets_punk.rb +1 -1
- data/app/routes/hello.rb +1 -1
- data/bin/punk +5 -5
- data/env/defaults.sh +3 -0
- data/lib/punk.rb +8 -9
- data/lib/punk/actions/sessions/create.rb +3 -3
- data/lib/punk/actions/sessions/verify.rb +2 -2
- data/lib/punk/commands/auth.rb +4 -4
- data/lib/punk/commands/generate.rb +5 -5
- data/lib/punk/commands/http.rb +4 -4
- data/lib/punk/commands/list.rb +10 -10
- data/lib/punk/core/app.rb +41 -41
- data/lib/punk/core/boot.rb +5 -5
- data/lib/punk/core/cli.rb +3 -3
- data/lib/punk/core/commander.rb +28 -28
- data/lib/punk/core/commands.rb +8 -8
- data/lib/punk/core/env.rb +27 -27
- data/lib/punk/core/exec.rb +8 -8
- data/lib/punk/core/interface.rb +19 -19
- data/lib/punk/core/load.rb +2 -2
- data/lib/punk/core/logger.rb +3 -3
- data/lib/punk/core/monkey.rb +1 -1
- data/lib/punk/core/pry.rb +2 -2
- data/lib/punk/core/settings.rb +4 -4
- data/lib/punk/core/version.rb +1 -1
- data/lib/punk/core/worker.rb +6 -6
- data/lib/punk/framework/all.rb +8 -8
- data/lib/punk/framework/model.rb +6 -5
- data/lib/punk/framework/plugins/all.rb +1 -1
- data/lib/punk/framework/plugins/validation.rb +8 -8
- data/lib/punk/framework/service.rb +5 -3
- data/lib/punk/framework/worker.rb +3 -3
- data/lib/punk/helpers/all.rb +5 -5
- data/lib/punk/helpers/loggable.rb +3 -3
- data/lib/punk/helpers/publishable.rb +1 -1
- data/lib/punk/helpers/renderable.rb +10 -10
- data/lib/punk/helpers/validatable.rb +7 -6
- data/lib/punk/migrations/001_punk.rb +12 -12
- data/lib/punk/models/group.rb +1 -1
- data/lib/punk/models/identity.rb +1 -1
- data/lib/punk/models/session.rb +7 -7
- data/lib/punk/models/tenant.rb +1 -1
- data/lib/punk/models/user.rb +2 -2
- data/lib/punk/plugins/all.rb +2 -2
- data/lib/punk/plugins/cors.rb +2 -2
- data/lib/punk/plugins/ssl.rb +1 -1
- data/lib/punk/routes/groups.rb +1 -1
- data/lib/punk/routes/plivo.rb +1 -1
- data/lib/punk/routes/sessions.rb +2 -2
- data/lib/punk/routes/swagger.rb +2 -2
- data/lib/punk/routes/tenants.rb +1 -1
- data/lib/punk/routes/users.rb +1 -1
- data/lib/punk/services/challenge_claim.rb +5 -5
- data/lib/punk/services/generate_swagger.rb +6 -6
- data/lib/punk/services/prove_claim.rb +1 -1
- data/lib/punk/startup/cache.rb +3 -3
- data/lib/punk/startup/database.rb +4 -4
- data/lib/punk/startup/environment.rb +6 -6
- data/lib/punk/startup/logger.rb +2 -2
- data/lib/punk/startup/task.rb +5 -5
- data/lib/punk/views/fail.rb +2 -2
- data/lib/punk/views/groups/list.rb +2 -2
- data/lib/punk/views/info.rb +2 -2
- data/lib/punk/views/plivo_store.rb +2 -2
- data/lib/punk/views/sessions/list.rb +2 -2
- data/lib/punk/views/sessions/pending.rb +2 -2
- data/lib/punk/views/tenants/list.rb +2 -2
- data/lib/punk/views/users/list.rb +2 -2
- data/lib/punk/views/users/show.rb +2 -2
- data/lib/punk/workers/geocode_session_worker.rb +3 -3
- data/lib/punk/workers/identify_session_worker.rb +1 -1
- data/lib/punk/workers/send_email_worker.rb +3 -3
- data/lib/punk/workers/send_sms_worker.rb +3 -3
- data/punk.gemspec +33 -31
- data/spec/actions/groups/punk/list_groups_action_spec.rb +9 -9
- data/spec/actions/sessions/punk/clear_session_action_spec.rb +11 -11
- data/spec/actions/sessions/punk/create_session_action_spec.rb +9 -9
- data/spec/actions/sessions/punk/list_sessions_action_spec.rb +8 -8
- data/spec/actions/sessions/punk/verify_session_action_spec.rb +24 -24
- data/spec/actions/tenants/punk/list_tenants_action_spec.rb +6 -6
- data/spec/actions/users/punk/list_group_users_action_spec.rb +6 -6
- data/spec/actions/users/punk/list_tenant_users_action_spec.rb +6 -6
- data/spec/factories/group.rb +1 -1
- data/spec/factories/group_user_metadata.rb +1 -1
- data/spec/factories/identity.rb +4 -4
- data/spec/factories/session.rb +1 -1
- data/spec/factories/tenant.rb +1 -1
- data/spec/factories/tenant_user_metadata.rb +1 -1
- data/spec/factories/user.rb +1 -1
- data/spec/lib/commands/generate_spec.rb +2 -2
- data/spec/lib/commands/list_spec.rb +2 -2
- data/spec/lib/commands/swagger_spec.rb +2 -2
- data/spec/lib/engine/punk_env_spec.rb +4 -4
- data/spec/lib/engine/punk_exec_spec.rb +2 -2
- data/spec/lib/engine/punk_init_spec.rb +2 -2
- data/spec/lib/engine/punk_store_spec.rb +2 -2
- data/spec/models/punk/group_spec.rb +4 -4
- data/spec/models/punk/group_user_metadata_spec.rb +2 -2
- data/spec/models/punk/identity_spec.rb +17 -17
- data/spec/models/punk/session_spec.rb +4 -4
- data/spec/models/punk/tenant_spec.rb +3 -3
- data/spec/models/punk/tenant_user_metadata_spec.rb +2 -2
- data/spec/models/punk/user_spec.rb +9 -9
- data/spec/routes/groups/get_groups_spec.rb +4 -4
- data/spec/routes/plivo/get_plivo_spec.rb +1 -1
- data/spec/routes/sessions/delete_session_spec.rb +1 -1
- data/spec/routes/sessions/get_sessions_spec.rb +5 -5
- data/spec/routes/sessions/patch_session_spec.rb +1 -1
- data/spec/routes/sessions/post_session_spec.rb +1 -1
- data/spec/routes/swagger/get_swagger_spec.rb +1 -1
- data/spec/routes/tenants/get_tenants_spec.rb +5 -5
- data/spec/routes/users/get_users_spec.rb +6 -6
- data/spec/services/punk/challenge_claim_service_spec.rb +2 -2
- data/spec/services/punk/create_identities_service_spec.rb +1 -1
- data/spec/services/punk/generate_swagger_service_spec.rb +2 -2
- data/spec/services/punk/prove_claim_service_spec.rb +2 -2
- data/spec/services/punk/secret_service_spec.rb +2 -2
- data/spec/spec_helper.rb +27 -27
- data/spec/views/punk/plivo_store_spec.rb +2 -2
- data/spec/views/sessions/punk/list_sessions_view_spec.rb +2 -2
- data/spec/views/sessions/punk/pending_session_view_spec.rb +2 -2
- data/spec/views/tenants/punk/list_tenants_view_spec.rb +2 -2
- data/spec/views/users/punk/list_groups_view_spec.rb +2 -2
- data/spec/views/users/punk/list_users_view_spec.rb +2 -2
- data/spec/workers/punk/geocode_session_worker_spec.rb +2 -2
- data/spec/workers/punk/identify_session_worker_spec.rb +3 -3
- data/spec/workers/punk/send_email_worker_spec.rb +1 -1
- metadata +24 -22
@@ -1,26 +1,26 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
describe PUNK::ListSessionsAction do
|
4
|
-
context
|
5
|
-
it
|
4
|
+
context "with no user provided" do
|
5
|
+
it "returns a validation error" do
|
6
6
|
view = described_class.run.result.render(:json)
|
7
|
-
expect(view).to match(
|
7
|
+
expect(view).to match("user is not present")
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
11
|
-
context
|
11
|
+
context "with a user provided" do
|
12
12
|
let(:user) { create(:user) }
|
13
13
|
let(:identity) { create(:identity, user: user) }
|
14
14
|
|
15
15
|
before do
|
16
|
-
create_list(:session, 3, state:
|
17
|
-
create_list(:session, 3, state:
|
16
|
+
create_list(:session, 3, state: "active")
|
17
|
+
create_list(:session, 3, state: "active", identity: identity)
|
18
18
|
end
|
19
19
|
|
20
|
-
it
|
20
|
+
it "returns active sessions that the user belongs to" do
|
21
21
|
expect(PUNK::Session.count).to eq(6)
|
22
22
|
view = JSON.parse(described_class.run(user: user).result.render(:json))
|
23
|
-
expect(view.map { |h| h[
|
23
|
+
expect(view.map { |h| h["id"] }.sort).to eq(user.active_sessions.map(&:id).sort)
|
24
24
|
end
|
25
25
|
end
|
26
26
|
end
|
@@ -1,31 +1,31 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
describe PUNK::VerifySessionAction do
|
4
|
-
context
|
5
|
-
it
|
4
|
+
context "with no session provided" do
|
5
|
+
it "returns a validation error" do
|
6
6
|
view = described_class.run.result.render(:json)
|
7
|
-
expect(view).to match(
|
7
|
+
expect(view).to match("session is not present")
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
11
|
-
context
|
12
|
-
it
|
11
|
+
context "with no secret provided" do
|
12
|
+
it "returns a validation error" do
|
13
13
|
session = create(:session)
|
14
14
|
view = described_class.run(session: session).result.render(:json)
|
15
|
-
expect(view).to match(
|
15
|
+
expect(view).to match("secret is not present")
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
-
context
|
20
|
-
it
|
19
|
+
context "with an inactive session provided" do
|
20
|
+
it "returns a validation error" do
|
21
21
|
session = create(:session)
|
22
|
-
view = described_class.run(session: session, secret:
|
23
|
-
expect(view).to match(
|
24
|
-
expect(view).to match(
|
22
|
+
view = described_class.run(session: session, secret: "xyzzy").result.render(:json)
|
23
|
+
expect(view).to match("session is not in pending state")
|
24
|
+
expect(view).to match("session may not verify")
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
|
-
context
|
28
|
+
context "with a pending session provided" do
|
29
29
|
let(:session) { create(:session) }
|
30
30
|
|
31
31
|
before do
|
@@ -33,26 +33,26 @@ describe PUNK::VerifySessionAction do
|
|
33
33
|
PUNK::ChallengeClaimService.run(session: session)
|
34
34
|
end
|
35
35
|
|
36
|
-
it
|
37
|
-
expect { described_class.run(session: session, secret:
|
36
|
+
it "returns an error if the secret is not correct" do
|
37
|
+
expect { described_class.run(session: session, secret: "qwerty") }.to raise_error(PUNK::BadRequest, "Secret is incorrect")
|
38
38
|
end
|
39
39
|
|
40
|
-
it
|
41
|
-
described_class.run(session: session, secret:
|
42
|
-
described_class.run(session: session, secret:
|
43
|
-
expect { described_class.run(session: session, secret:
|
40
|
+
it "expires the session after three failed attempts" do
|
41
|
+
described_class.run(session: session, secret: "qwerty") rescue nil # rubocop:disable Style/RescueModifier
|
42
|
+
described_class.run(session: session, secret: "qwerty") rescue nil # rubocop:disable Style/RescueModifier
|
43
|
+
expect { described_class.run(session: session, secret: "qwerty") }.to raise_error(PUNK::BadRequest, "Too many attempts")
|
44
44
|
end
|
45
45
|
|
46
|
-
it
|
46
|
+
it "expires the session if it is more than five minutes old" do
|
47
47
|
Timecop.travel(5.minutes.from_now)
|
48
|
-
view = described_class.run(session: session, secret:
|
49
|
-
expect(view).to match(
|
48
|
+
view = described_class.run(session: session, secret: "xyzzy").result.render(:json)
|
49
|
+
expect(view).to match("session may not verify")
|
50
50
|
expect(session.expired?).to be(true)
|
51
51
|
end
|
52
52
|
|
53
|
-
it
|
54
|
-
view = described_class.run(session: session, secret:
|
55
|
-
expect(view).to match(
|
53
|
+
it "verifies the session if the secret is correct" do
|
54
|
+
view = described_class.run(session: session, secret: "xyzzy").result.render(:json)
|
55
|
+
expect(view).to match("We have succesfully verified your identity")
|
56
56
|
expect(session.active?).to be(true)
|
57
57
|
end
|
58
58
|
end
|
@@ -1,14 +1,14 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
describe PUNK::ListTenantsAction do
|
4
|
-
context
|
5
|
-
it
|
4
|
+
context "with no user provided" do
|
5
|
+
it "returns a validation error" do
|
6
6
|
view = described_class.run.result.render(:json)
|
7
|
-
expect(view).to match(
|
7
|
+
expect(view).to match("user is not present")
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
11
|
-
context
|
11
|
+
context "with a user provided" do
|
12
12
|
let(:user) { create(:user) }
|
13
13
|
|
14
14
|
before do
|
@@ -16,10 +16,10 @@ describe PUNK::ListTenantsAction do
|
|
16
16
|
3.times { create(:tenant).add_user(user) }
|
17
17
|
end
|
18
18
|
|
19
|
-
it
|
19
|
+
it "returns tenants that the user belongs to" do
|
20
20
|
expect(PUNK::Tenant.count).to eq(6)
|
21
21
|
view = JSON.parse(described_class.run(user: user).result.render(:json))
|
22
|
-
expect(view.map { |h| h[
|
22
|
+
expect(view.map { |h| h["id"] }.sort).to eq(user.tenants.map(&:id).sort)
|
23
23
|
end
|
24
24
|
end
|
25
25
|
end
|
@@ -1,14 +1,14 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
describe PUNK::ListGroupUsersAction do
|
4
|
-
context
|
5
|
-
it
|
4
|
+
context "with no group provided" do
|
5
|
+
it "returns a validation error" do
|
6
6
|
view = described_class.run.result.render(:json)
|
7
|
-
expect(view).to match(
|
7
|
+
expect(view).to match("group is not present")
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
11
|
-
context
|
11
|
+
context "with valid arguments" do
|
12
12
|
let(:group) { create(:group) }
|
13
13
|
let(:users) { create_list(:user, 3) }
|
14
14
|
|
@@ -17,10 +17,10 @@ describe PUNK::ListGroupUsersAction do
|
|
17
17
|
users.each { |user| group.add_user(user) }
|
18
18
|
end
|
19
19
|
|
20
|
-
it
|
20
|
+
it "returns users that are members of the given group" do
|
21
21
|
expect(PUNK::User.count).to eq(5)
|
22
22
|
view = JSON.parse(described_class.run(group: group).result.render(:json))
|
23
|
-
expect(view.map { |h| h[
|
23
|
+
expect(view.map { |h| h["id"] }.sort).to eq(group.users.map(&:id).sort)
|
24
24
|
end
|
25
25
|
end
|
26
26
|
end
|
@@ -1,14 +1,14 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
describe PUNK::ListTenantUsersAction do
|
4
|
-
context
|
5
|
-
it
|
4
|
+
context "with no tenant provided" do
|
5
|
+
it "returns a validation error" do
|
6
6
|
view = described_class.run.result.render(:json)
|
7
|
-
expect(view).to match(
|
7
|
+
expect(view).to match("tenant is not present")
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
11
|
-
context
|
11
|
+
context "with valid arguments" do
|
12
12
|
let(:tenant) { create(:tenant) }
|
13
13
|
let(:users) { create_list(:user, 3) }
|
14
14
|
|
@@ -17,10 +17,10 @@ describe PUNK::ListTenantUsersAction do
|
|
17
17
|
users.each { |user| tenant.add_user(user) }
|
18
18
|
end
|
19
19
|
|
20
|
-
it
|
20
|
+
it "returns users that are members of the given tenant" do
|
21
21
|
expect(PUNK::User.count).to eq(5)
|
22
22
|
view = JSON.parse(described_class.run(tenant: tenant).result.render(:json))
|
23
|
-
expect(view.map { |h| h[
|
23
|
+
expect(view.map { |h| h["id"] }.sort).to eq(tenant.users.map(&:id).sort)
|
24
24
|
end
|
25
25
|
end
|
26
26
|
end
|
data/spec/factories/group.rb
CHANGED
data/spec/factories/identity.rb
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
FactoryBot.define do
|
4
|
-
factory :identity, class:
|
4
|
+
factory :identity, class: "PUNK::Identity" do
|
5
5
|
to_create(&:save)
|
6
6
|
|
7
7
|
user
|
8
8
|
|
9
|
-
claim_type { [
|
9
|
+
claim_type { ["email", "phone"].sample }
|
10
10
|
claim do
|
11
11
|
case claim_type
|
12
|
-
when
|
12
|
+
when "email"
|
13
13
|
Faker::Internet.email
|
14
|
-
when
|
14
|
+
when "phone"
|
15
15
|
generate(:phone)
|
16
16
|
end
|
17
17
|
end
|
data/spec/factories/session.rb
CHANGED
data/spec/factories/tenant.rb
CHANGED
data/spec/factories/user.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
describe
|
4
|
-
context
|
3
|
+
describe "generate command", type: :feature do
|
4
|
+
context "when no tests have been written" do
|
5
5
|
it 'displays "not yet implemented"'
|
6
6
|
end
|
7
7
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
describe
|
4
|
-
context
|
3
|
+
describe "list command", type: :feature do
|
4
|
+
context "when no tests have been written" do
|
5
5
|
it 'displays "not yet implemented"'
|
6
6
|
end
|
7
7
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
describe
|
4
|
-
context
|
3
|
+
describe "swagger command", type: :feature do
|
4
|
+
context "when no tests have been written" do
|
5
5
|
it 'displays "not yet implemented"'
|
6
6
|
end
|
7
7
|
end
|
@@ -1,12 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
describe PUNK do
|
4
|
-
describe
|
5
|
-
it
|
6
|
-
expect(described_class.get.trace).to eq(
|
4
|
+
describe ".env" do
|
5
|
+
it "loads environment" do
|
6
|
+
expect(described_class.get.trace).to eq("spec_test")
|
7
7
|
end
|
8
8
|
|
9
|
-
it
|
9
|
+
it "loads configuration" do
|
10
10
|
expect(described_class.env.to_sym).to eq(:test)
|
11
11
|
end
|
12
12
|
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
describe PUNK do
|
4
|
-
describe
|
5
|
-
it
|
4
|
+
describe ".init" do
|
5
|
+
it "cannot be called twice" do
|
6
6
|
expect { described_class.init }.to raise_error(PUNK::InternalServerError, "Cannot call PUNK.init multiple times!")
|
7
7
|
end
|
8
8
|
end
|
@@ -8,7 +8,7 @@ describe PUNK::Group do
|
|
8
8
|
it "is assigned a uuid on save" do
|
9
9
|
group = build(:group)
|
10
10
|
expect(group.id).to be_nil
|
11
|
-
group.
|
11
|
+
group.save_changes
|
12
12
|
expect(valid_uuid?(group.id)).to be(true)
|
13
13
|
end
|
14
14
|
|
@@ -21,7 +21,7 @@ describe PUNK::Group do
|
|
21
21
|
it "is invalid without a name" do
|
22
22
|
group = build(:group, name: nil)
|
23
23
|
expect(group.valid?).to be(false)
|
24
|
-
expect(group.errors[:name].first).to eq(
|
24
|
+
expect(group.errors[:name].first).to eq("is not present")
|
25
25
|
end
|
26
26
|
|
27
27
|
it "is valid without an icon" do
|
@@ -32,13 +32,13 @@ describe PUNK::Group do
|
|
32
32
|
it "is invalid if the icon is not a URL" do
|
33
33
|
group = build(:group, icon: Faker::Alphanumeric.alpha)
|
34
34
|
expect(group.valid?).to be(false)
|
35
|
-
expect(group.errors[:icon].first).to eq(
|
35
|
+
expect(group.errors[:icon].first).to eq("is not a URL")
|
36
36
|
end
|
37
37
|
|
38
38
|
it "must belong to a tenant" do
|
39
39
|
group = build(:group, tenant: nil)
|
40
40
|
expect(group.valid?).to be(false)
|
41
|
-
expect(group.errors[:tenant].first).to eq(
|
41
|
+
expect(group.errors[:tenant].first).to eq("is not present")
|
42
42
|
end
|
43
43
|
|
44
44
|
it "can have multiple members" do
|
@@ -8,13 +8,13 @@ describe PUNK::GroupUserMetadata do
|
|
8
8
|
it "is invalid without a group" do
|
9
9
|
group_user_metadata = build(:group_user_metadata, group: nil)
|
10
10
|
expect(group_user_metadata.valid?).to be(false)
|
11
|
-
expect(group_user_metadata.errors[:group].first).to eq(
|
11
|
+
expect(group_user_metadata.errors[:group].first).to eq("is not present")
|
12
12
|
end
|
13
13
|
|
14
14
|
it "is invalid without a user" do
|
15
15
|
group_user_metadata = build(:group_user_metadata, user: nil)
|
16
16
|
expect(group_user_metadata.valid?).to be(false)
|
17
|
-
expect(group_user_metadata.errors[:user].first).to eq(
|
17
|
+
expect(group_user_metadata.errors[:user].first).to eq("is not present")
|
18
18
|
end
|
19
19
|
|
20
20
|
it "displays as the two IDs concatenated" do
|
@@ -1,58 +1,58 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
describe PUNK::Identity do
|
4
|
-
it
|
4
|
+
it "is valid with valid attributes" do
|
5
5
|
expect { create(:identity) }.not_to raise_error
|
6
6
|
end
|
7
7
|
|
8
|
-
it
|
9
|
-
identity = build(:identity, claim_type:
|
8
|
+
it "must claim an email or a phone" do
|
9
|
+
identity = build(:identity, claim_type: "zork", claim: "xyzzy")
|
10
10
|
expect(identity.valid?).to be(false)
|
11
|
-
expect(identity.errors[:claim_type].first).to eq(
|
11
|
+
expect(identity.errors[:claim_type].first).to eq("is not in range or set: [:email, :phone]")
|
12
12
|
end
|
13
13
|
|
14
|
-
it
|
14
|
+
it "is assigned a uuid on save" do
|
15
15
|
identity = build(:identity)
|
16
16
|
expect(identity.id).to be_nil
|
17
|
-
identity.
|
17
|
+
identity.save_changes
|
18
18
|
expect(valid_uuid?(identity.id)).to be(true)
|
19
19
|
end
|
20
20
|
|
21
|
-
it
|
21
|
+
it "can be saved with a custom uuid" do
|
22
22
|
uuid = generate(:uuid)
|
23
23
|
identity = create(:identity, id: uuid)
|
24
24
|
expect(identity.id).to eq(uuid)
|
25
25
|
end
|
26
26
|
|
27
|
-
it
|
27
|
+
it "may belong to a user" do
|
28
28
|
identity_with_user = create(:identity)
|
29
29
|
expect(identity_with_user.user).to exist
|
30
30
|
identity_without_user = create(:identity, user: nil)
|
31
31
|
expect(identity_without_user.user).to be_nil
|
32
32
|
end
|
33
33
|
|
34
|
-
it
|
35
|
-
identity_with_email = build(:identity, claim_type:
|
34
|
+
it "has an email? accessor" do
|
35
|
+
identity_with_email = build(:identity, claim_type: "email")
|
36
36
|
expect(identity_with_email.email?).to be(true)
|
37
|
-
identity_without_email = build(:identity, claim_type:
|
37
|
+
identity_without_email = build(:identity, claim_type: "phone")
|
38
38
|
expect(identity_without_email.email?).to be(false)
|
39
39
|
end
|
40
40
|
|
41
|
-
it
|
42
|
-
identity_with_phone = create(:identity, claim_type:
|
41
|
+
it "has a phone? accessor" do
|
42
|
+
identity_with_phone = create(:identity, claim_type: "phone")
|
43
43
|
expect(identity_with_phone.phone?).to be(true)
|
44
|
-
identity_without_phone = create(:identity, claim_type:
|
44
|
+
identity_without_phone = create(:identity, claim_type: "email")
|
45
45
|
expect(identity_without_phone.phone?).to be(false)
|
46
46
|
end
|
47
47
|
|
48
|
-
it
|
48
|
+
it "has a unique claim" do
|
49
49
|
identity = create(:identity)
|
50
50
|
duplicate_identity = build(:identity, claim_type: identity.claim_type, claim: identity.claim)
|
51
51
|
expect(duplicate_identity.valid?).to be(false)
|
52
|
-
expect(duplicate_identity.errors[:claim].first).to eq(
|
52
|
+
expect(duplicate_identity.errors[:claim].first).to eq("is already taken")
|
53
53
|
end
|
54
54
|
|
55
|
-
it
|
55
|
+
it "can have multiple sessions" do
|
56
56
|
identity = create(:identity)
|
57
57
|
expect(identity.sessions.count).to eq(0)
|
58
58
|
create_list(:session, 3, identity: identity)
|