Permalink
Browse files

Add create_submission method to helpers

  • Loading branch information...
1 parent 3b6c38e commit ae46a960915c06059d73f5b69d4656cfb226ceac @jordanbyron jordanbyron committed Jun 13, 2011
Showing with 17 additions and 26 deletions.
  1. +3 −11 test/integration/puzzle/comments_test.rb
  2. +8 −0 test/test_helper.rb
  3. +6 −15 test/unit/user_test.rb
View
14 test/integration/puzzle/comments_test.rb
@@ -2,14 +2,6 @@
class Puzzle
class CommentsTest < ActionDispatch::IntegrationTest
- def create_correct_submission(user, puzzle)
- submission = user.submissions.create do |submission|
- submission.puzzle = puzzle
- submission.file = Tempfile.new("solution")
- submission.correct = true
- end
- submission.update_attribute(:correct, true)
- end
setup do
@user = Factory(:user, :name => "Normal User")
@@ -20,9 +12,9 @@ def create_correct_submission(user, puzzle)
end
test "only show normal user in the solved by list" do
- create_correct_submission @user, @puzzle
- create_correct_submission @admin, @puzzle
- create_correct_submission @draft_access, @puzzle
+ create_submission @puzzle, @user, true
+ create_submission @puzzle, @admin, true
+ create_submission @puzzle, @draft_access, true
sign_user_in
View
8 test/test_helper.rb
@@ -21,6 +21,14 @@ def build_puzzle
)
end
+ def create_submission(puzzle, user, correct)
+ Submission.create(
+ :user => user,
+ :puzzle => puzzle,
+ :file => Tempfile.new('solution')
+ ).update_attribute(:correct, correct)
+ end
+
def cleanup_attachment(attachment)
FileUtils.rm_rf(attachment.directory)
end
View
21 test/unit/user_test.rb
@@ -17,8 +17,8 @@ def setup
end
test "leaderboard is sorted by number of correct solutions" do
- 5.times { |i| create_submission(@harry, i.zero?) }
- 2.times { |i| create_submission(@sally, true) }
+ 5.times { |i| create_submission(Factory(:puzzle), @harry, i.zero?) }
+ 2.times { |i| create_submission(Factory(:puzzle), @sally, true) }
leaderboard = User.leaderboard
assert_equal [@sally.id, @harry.id], leaderboard.map(&:id)
@@ -29,8 +29,8 @@ def setup
end
test "ties are broken by the fastest submission" do
- 2.times { |i| create_submission(@harry, true) }
- 2.times { |i| create_submission(@sally, true) }
+ 2.times { |i| create_submission(Factory(:puzzle), @harry, true) }
+ 2.times { |i| create_submission(Factory(:puzzle), @sally, true) }
assert_equal [@harry.id, @sally.id], User.leaderboard.map(&:id)
end
@@ -39,19 +39,10 @@ def setup
admin = @harry
admin.update_attribute(:admin, true)
- 2.times { |i| create_submission(admin, true) }
- 2.times { |i| create_submission(@sally, true) }
+ 2.times { |i| create_submission(Factory(:puzzle), admin, true) }
+ 2.times { |i| create_submission(Factory(:puzzle), @sally, true) }
assert_equal [@sally.id], User.leaderboard.map(&:id)
end
- private
-
- def create_submission(user, correct)
- Submission.create(
- :user => user,
- :puzzle => Factory(:puzzle),
- :file => Tempfile.new('solution')
- ).update_attribute(:correct, correct)
- end
end

0 comments on commit ae46a96

Please sign in to comment.