Skip to content

Commit 5ac85ba

Browse files
Spec form Fillin valid
1 parent de93b19 commit 5ac85ba

File tree

9 files changed

+42
-136
lines changed

9 files changed

+42
-136
lines changed

app/controllers/decidim/extends/controllers/confirmation_controller.rb

Whitespace-only changes.

app/controllers/decidim/socio_demographic_authorization_handler/admin/application_controller.rb

Lines changed: 0 additions & 15 deletions
This file was deleted.

app/controllers/decidim/socio_demographic_authorization_handler/application_controller.rb

Lines changed: 0 additions & 13 deletions
This file was deleted.

app/controllers/decidim/socio_demographic_authorization_handler/socio_demographic_authorization_controller.rb

Lines changed: 0 additions & 18 deletions
This file was deleted.
Lines changed: 28 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,31 @@
11
# frozen_string_literal: true
22

3-
# An example authorization handler used so that users can be verified against
4-
# third party systems.
5-
#
6-
# You should probably rename this class and file to match your needs.
7-
#
8-
# If you need a custom form to be rendered, you can create a file matching the
9-
# class name named "_form".
10-
#
11-
# Example:
12-
#
13-
# A handler named Decidim::CensusHandler would look for its partial in:
14-
# decidim/census/form
15-
#
16-
# When testing your authorization handler, add this line to be sure it has a
17-
# valid public api:
18-
#
19-
# it_behaves_like "an authorization handler"
20-
#
21-
# See Decidim::AuthorizationHandler for more documentation.
22-
class SocioDemographicAuthorizationHandler < Decidim::AuthorizationHandler
23-
24-
attribute :scope, String
25-
attribute :gender, String
26-
attribute :age, String
27-
28-
GENDER = %w[man woman undefined].freeze
29-
SCOPES = Decidim::Scope.all.map { |scope| scope.code.downcase }
30-
AGE_SLICE = %w[16-25 26-45 46-65 65+].freeze
31-
32-
validates :scope,
33-
inclusion: { in: SCOPES },
34-
presence: true
35-
36-
validates :gender,
37-
inclusion: { in: GENDER },
38-
presence: true
39-
40-
validates :age,
41-
inclusion: { in: AGE_SLICE },
42-
presence: true
43-
44-
def metadata
45-
super.merge(scope: scope, gender: gender, age: age)
46-
end
473

48-
end
4+
# Allows to create a form for simple Socio Demographic authorization
5+
class SocioDemographicAuthorizationHandler < Decidim::AuthorizationHandler
6+
7+
attribute :scope, String
8+
attribute :gender, String
9+
attribute :age, String
10+
11+
SCOPES = Decidim::Scope.all.map { |scope| scope.code.downcase }
12+
GENDER = %w(man woman undefined).freeze
13+
AGE_SLICE = %w(16-25 26-45 46-65 65+).freeze
14+
15+
validates :scope,
16+
inclusion: { in: SCOPES },
17+
presence: true
18+
19+
validates :gender,
20+
inclusion: { in: GENDER },
21+
presence: true
22+
23+
validates :age,
24+
inclusion: { in: AGE_SLICE },
25+
presence: true
26+
27+
def metadata
28+
super.merge(scope: scope, gender: gender, age: age)
29+
end
30+
31+
end

lib/decidim/extends/controllers/confirmations_controller_extend.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ def after_confirmation_path_for(resource_name, resource)
1414
sign_in(resource) unless user_signed_in? # In case you want to sign in the user
1515

1616
if first_login_and_not_authorized?(resource)
17-
# TODO: new_authorization_path est une méthode d'ENGINE !!
1817
Decidim::Verifications.find_workflow_manifest :socio_demographic_authorization_handler .new_authorization_path(action: :new)
1918
else
2019
super

lib/decidim/socio_demographic_authorization_handler.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# frozen_string_literal: true
22

33
require "decidim/socio_demographic_authorization_handler/workflow"
4-
require "decidim/socio_demographic_authorization_handler/socio_demographic_authorization_handler"
4+
#require "decidim/socio_demographic_authorization_handler/socio_demographic_authorization_handler"
55

66
module Decidim
77
# This namespace holds the logic of the `SocioDemographicAuthorizationHandler` component. This component

lib/decidim/socio_demographic_authorization_handler/socio_demographic_authorization_handler.rb

Lines changed: 0 additions & 33 deletions
This file was deleted.

spec/system/authorizations_spec.rb

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
context "when a new user" do
1111
let(:organization) { create :organization, available_authorizations: authorizations }
12+
let!(:scopes) { create_list(:scope, 9, organization: organization) }
1213

1314
let(:user) { create(:user, :confirmed, organization: organization) }
1415

@@ -27,9 +28,9 @@
2728
end
2829

2930
it "redirects the user to the authorization form after the first sign in" do
30-
fill_in :scope, with: organization.scopes
31-
fill_in :gender, with: %w(Man Woman Undefined)
32-
fill_in :age, with: %w(16-25 26-45 46-65 65+)
31+
find('select#authorization_handler_scope').find("option", match: :first).select_option
32+
find('select#authorization_handler_gender').find("option", match: :first).select_option
33+
find('select#authorization_handler_age').find("option", match: :first).select_option
3334

3435
click_button "Send"
3536
expect(page).to have_content("You've been successfully authorized")
@@ -82,9 +83,10 @@
8283
click_link "Authorizations"
8384
click_link "Socio Demographic Authorization"
8485

85-
fill_in "Document number", with: "123456789X"
86-
page.execute_script("$('#authorization_handler_birthday').focus()")
87-
page.find(".datepicker-dropdown .day", text: "12").click
86+
fill_in :scope, with: organization.scopes
87+
fill_in :gender, with: %w(Man Woman Undefined)
88+
fill_in :age, with: %w(16-25 26-45 46-65 65+)
89+
8890
click_button "Send"
8991

9092
expect(page).to have_content("You've been successfully authorized")
@@ -107,9 +109,10 @@
107109
click_link "Authorizations"
108110
click_link "Socio Demographic Authorization"
109111

110-
fill_in "Document number", with: "12345678"
111-
page.execute_script("$('#authorization_handler_birthday').focus()")
112-
page.find(".datepicker-dropdown .day", text: "12").click
112+
fill_in :scope, with: organization.scopes
113+
fill_in :gender, with: %w(Man Woman Undefined)
114+
fill_in :age, with: %w(16-25 26-45 46-65 65+)
115+
113116
click_button "Send"
114117

115118
expect(page).to have_content("There was a problem creating the authorization.")
@@ -171,7 +174,7 @@
171174
click_link "Socio Demographic Authorization"
172175
end
173176

174-
fill_in "Document number", with: "123456789X"
177+
fill_in :scope, with: organization.scopes
175178
click_button "Send"
176179

177180
expect(page).to have_content("You've been successfully authorized")

0 commit comments

Comments
 (0)