Skip to content
This repository was archived by the owner on Nov 21, 2018. It is now read-only.

Commit 1495fca

Browse files
committed
Get all tests working
1 parent 8a4420d commit 1495fca

File tree

7 files changed

+22
-35
lines changed

7 files changed

+22
-35
lines changed

app/controllers/punishments_controller.rb

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -132,20 +132,6 @@ def edit
132132

133133
return redirect_to_back punishment_path(@punishment), :alert => 'You do not have permission to edit this punishment.' unless @can_delete || !@editable.empty?
134134

135-
if @editable.include?(:expire)
136-
@expires = Hash.new
137-
@punishment.expire = Time.at(0) if @punishment.expire == nil
138-
139-
@days_total = (@punishment.expire - @punishment.date).in_days.to_i
140-
@days_left = (@punishment.expire - Time.now).in_days.to_i
141-
142-
@expires.merge!({"Never - Permanent ban" => nil})
143-
144-
60.downto(-60) do |n|
145-
@expires.merge!({n.to_s + " day" + (n == 1 ? "" : "s") + " from now - " + (n - @days_left + @days_total).to_s + " day ban" => @punishment.expire - (@days_left - n).days})
146-
end
147-
end
148-
149135
if @editable.include?(:type)
150136
@issueable_types = Punishment::Type::ALL.select {|type| Punishment.can_issue?(type, current_user) }
151137
@editable.delete(:type) if @issueable_types.empty?

app/helpers/user_helper.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ def html_color(user)
7272
user.html_color
7373
end
7474

75-
PROFILE_URL_REGEX = %r<http(?:s?)://oc\.tc/(?:users/)?(\w{1,16})\b>
76-
AVATAR_URL_REGEX = %r<http(?:s?)://avatar\.oc\.tc/(\w{1,16})\b>
75+
PROFILE_URL_REGEX = %r<http(?:s?)://#{Regexp.quote(ORG::DOMAIN)}/(?:users/)?(\w{1,16})\b>
76+
AVATAR_URL_REGEX = %r<http(?:s?)://avatar\.#{Regexp.quote(ORG::DOMAIN)}/(\w{1,16})\b>
7777

7878
def transform_user_tags(text)
7979
text.gsub(/\[(user|avatar|avatar[_-]user):(\w{1,16}|[0-9a-fA-F-]{32,})\]/) do |tag|
@@ -88,7 +88,7 @@ def transform_user_tags(text)
8888
end
8989

9090
def transform_profile_urls(text)
91-
text.gsub(%r<http(?:s?)://oc\.tc/(?:users/)?(\w{1,16})\b>).each do |url|
91+
text.gsub(%r<http(?:s?)://#{Regexp.quote(ORG::DOMAIN)}/(?:users/)?(\w{1,16})\b>).each do |url|
9292
begin
9393
username = $1
9494
uri = URI.parse(url)
@@ -104,7 +104,7 @@ def transform_profile_urls(text)
104104
end
105105

106106
def transform_avatar_url_prefixes(text)
107-
text.gsub(%r<http(?:s?)://avatar\.oc\.tc/(\w{1,16})\b>).each do |url|
107+
text.gsub(%r<http(?:s?)://avatar\.#{Regexp.quote(ORG::DOMAIN)}/(\w{1,16})\b>).each do |url|
108108
username = $1
109109
if user = User.by_past_username(username)
110110
yield user

app/models/server/rotations.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ module Rotations
1919

2020
# Lines from the rotation file, if any
2121
attr_cached :rotation_entries do
22-
fn = rotation_path
23-
if File.exists?(fn)
22+
if fn = rotation_path and File.exists?(fn)
2423
File.read(fn).lines
2524
else
2625
[]
@@ -39,7 +38,9 @@ module Rotations
3938
end # included do
4039

4140
def rotation_path
42-
Repository[:rotations].join_path(rotation_file || File.join(datacenter, name))
41+
if repo = Repository[:rotations]
42+
repo.join_path(rotation_file || File.join(datacenter, name))
43+
end
4344
end
4445

4546
def rotation_map_ids

app/views/devise/registrations/edit.haml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,7 @@
8989
%a{href: user_path(current_user)} profile
9090
%p
9191
If you are a member of the
92-
%a{href: letsplay_path} Let's Play
93-
group, you will also get a YouTube badge, and your channel will be listed on the
92+
Let's Play group, you will also get a YouTube badge, and your channel will be listed on the
9493
%a{href: channels_path} channels
9594
page.
9695
.row

test/factories/punishment_factories.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
FactoryGirl.define do
22
factory :punishment do
33
type Punishment::Type::BAN
4+
playing_time_ms 0
45
sequence(:reason) {|n| "Reason for punishment #{n}" }
56
sequence(:punished) {|n| create(:user, username: "BadPlayer#{n}") }
67
sequence(:punisher) {|n| create(:user, username: "Moderator#{n}") }

test/functional/registrations_controller_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class RegistrationsControllerTest < ActionController::TestCase
1010
get :new
1111

1212
assert_response :success
13-
assert_select '#token', text: /[0-9a-z]{12}\.register\.oc\.tc/
13+
assert_select '#token', text: /[0-9a-z]{12}\.register/
1414
end
1515

1616
test "send email confirmation" do

test/unit/punishment_test.rb

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,33 +36,33 @@ def add_playing_time(user, duration)
3636
guilty = create(:user)
3737
create(:kick, punished: guilty)
3838

39-
assert_equal (Type::BAN, 7.days), Punishment.calculate_next_game(guilty)
39+
assert_equal [Punishment::Type::BAN, 7.days], Punishment.calculate_next_game(guilty)
4040

4141
create(:ban, punished: guilty)
4242

43-
assert_equal (Type::BAN, nil), Punishment.calculate_next_game(guilty)
43+
assert_equal [Punishment::Type::BAN, nil], Punishment.calculate_next_game(guilty)
4444
end
4545

4646
test "forum punish sequence" do
4747
guilty = create(:user)
4848

49-
assert_equal (Type::FORUM_WARN, nil), Punishment.calculate_next_forum(guilty)
49+
assert_equal [Punishment::Type::FORUM_WARN, nil], Punishment.calculate_next_forum(guilty)
5050

5151
create(:forum_warn, punished: guilty)
5252

53-
assert_equal (Type::FORUM_WARN, nil), Punishment.calculate_next_forum(guilty)
53+
assert_equal [Punishment::Type::FORUM_WARN, nil], Punishment.calculate_next_forum(guilty)
5454

5555
create(:forum_warn, punished: guilty)
5656

57-
assert_equal (Type::FORUM_BAN, 7.days), Punishment.calculate_next_forum(guilty)
57+
assert_equal [Punishment::Type::FORUM_BAN, 7.days], Punishment.calculate_next_forum(guilty)
5858

5959
create(:forum_ban, punished: guilty)
6060

61-
assert_equal (Type::FORUM_BAN, 30.days), Punishment.calculate_next_forum(guilty)
61+
assert_equal [Punishment::Type::FORUM_BAN, 30.days], Punishment.calculate_next_forum(guilty)
6262

6363
create(:forum_ban, punished: guilty)
6464

65-
assert_equal (Type::FORUM_BAN, nil), Punishment.calculate_next_forum(guilty)
65+
assert_equal [Punishment::Type::FORUM_BAN, nil], Punishment.calculate_next_forum(guilty)
6666
end
6767

6868
test "punish sequence stale" do
@@ -71,11 +71,11 @@ def add_playing_time(user, duration)
7171

7272
create(:kick, punished: guilty)
7373

74-
assert_equal (Type::BAN, 7.days), Punishment.calculate_next_game(guilty)
74+
assert_equal [Punishment::Type::BAN, 7.days], Punishment.calculate_next_game(guilty)
7575

7676
Timecop.freeze Punishment::STALE_REAL_TIME + 1.day do
7777
add_playing_time guilty, ( Punishment::STALE_PLAY_TIME + 1.second )
78-
assert_equal (Type::KICK, nil), Punishment.calculate_next_game(guilty)
78+
assert_equal [Punishment::Type::KICK, nil], Punishment.calculate_next_game(guilty)
7979
end
8080
end
8181
end
@@ -87,10 +87,10 @@ def add_playing_time(user, duration)
8787
create(:forum_warn, punished: guilty)
8888
create(:forum_warn, punished: guilty)
8989

90-
assert_equal (Type::FORUM_BAN, 7.days), Punishment.calculate_next_forum(guilty)
90+
assert_equal [Punishment::Type::FORUM_BAN, 7.days], Punishment.calculate_next_forum(guilty)
9191

9292
Timecop.freeze Punishment::FORUM_STALE_TIME + 1.day do
93-
assert_equal (Type::FORUM_WARN, nil), Punishment.calculate_next_forum(guilty)
93+
assert_equal [Punishment::Type::FORUM_WARN, nil], Punishment.calculate_next_forum(guilty)
9494
end
9595
end
9696
end

0 commit comments

Comments
 (0)