forked from mastodon/mastodon
-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
40 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -392,47 +392,50 @@ def create_other_user | |
post :create, params: { user: { account_attributes: { username: 'test' }, email: '[email protected]', password: '12345678', password_confirmation: '12345678', agreement: 'true' } } | ||
end | ||
|
||
let(:start_hour) { 9 } | ||
let(:end_hour) { 12 } | ||
|
||
before do | ||
Setting.registrations_mode = 'open' | ||
Setting.registrations_start_hour = start_hour | ||
Setting.registrations_end_hour = end_hour | ||
request.headers['Accept-Language'] = accept_language | ||
|
||
travel_to Time.now.utc.beginning_of_day + 10.hours | ||
end | ||
|
||
it 'creates user' do | ||
subject | ||
user = User.find_by(email: '[email protected]') | ||
expect(user).to_not be_nil | ||
expect(user.locale).to eq(accept_language) | ||
end | ||
|
||
context 'when out of range' do | ||
let(:start_hour) { 12 } | ||
let(:end_hour) { 15 } | ||
shared_examples 'registration with time' do |header, start_hour_val, end_hour_val, secondary_start_hour_val, secondary_end_hour_val, result| # rubocop:disable Metrics/ParameterLists | ||
context header do | ||
let(:start_hour) { start_hour_val } | ||
let(:end_hour) { end_hour_val } | ||
let(:secondary_start_hour) { secondary_start_hour_val } | ||
let(:secondary_end_hour) { secondary_end_hour_val } | ||
|
||
before do | ||
Setting.registrations_mode = 'open' | ||
Setting.registrations_start_hour = start_hour | ||
Setting.registrations_end_hour = end_hour | ||
Setting.registrations_secondary_start_hour = secondary_start_hour | ||
Setting.registrations_secondary_end_hour = secondary_end_hour | ||
request.headers['Accept-Language'] = accept_language | ||
|
||
travel_to Time.now.utc.beginning_of_day + 10.hours | ||
end | ||
|
||
it 'does not create user' do | ||
subject | ||
user = User.find_by(email: '[email protected]') | ||
expect(user).to be_nil | ||
if result | ||
it 'creates user' do | ||
subject | ||
user = User.find_by(email: '[email protected]') | ||
expect(user).to_not be_nil | ||
expect(user.locale).to eq(accept_language) | ||
end | ||
else | ||
it 'does not create user' do | ||
subject | ||
user = User.find_by(email: '[email protected]') | ||
expect(user).to be_nil | ||
end | ||
end | ||
end | ||
end | ||
|
||
context 'when invalid range' do | ||
let(:start_hour) { 20 } | ||
let(:end_hour) { 15 } | ||
|
||
it 'creates user' do | ||
subject | ||
user = User.find_by(email: '[email protected]') | ||
expect(user).to_not be_nil | ||
expect(user.locale).to eq(accept_language) | ||
end | ||
end | ||
it_behaves_like 'registration with time', 'time range is not set', 0, 24, 0, 0, true | ||
it_behaves_like 'registration with time', 'time range is set', 9, 12, 0, 0, true | ||
it_behaves_like 'registration with time', 'time range is out of range', 12, 15, 0, 0, false | ||
it_behaves_like 'registration with time', 'time range is invalid', 20, 15, 0, 0, true | ||
it_behaves_like 'registration with time', 'secondary time range is set', 0, 4, 9, 12, true | ||
it_behaves_like 'registration with time', 'secondary time range is out of range', 0, 4, 12, 15, false | ||
it_behaves_like 'registration with time', 'secondary time range is invalid', 0, 4, 20, 15, false | ||
it_behaves_like 'registration with time', 'both time range are invalid', 4, 0, 20, 15, true | ||
it_behaves_like 'registration with time', 'only secondary time range is set', 0, 0, 9, 12, true | ||
end | ||
|
||
include_examples 'checks for enabled registrations', :create | ||
|