Permalink
Browse files

Don't let people post the same fix twice

  • Loading branch information...
1 parent cabb376 commit 5ee369b0f741419985dbf50f0a9da204281f8473 @radar radar committed Jun 16, 2009
Showing with 17 additions and 4 deletions.
  1. +9 −0 features/fixes.feature
  2. +1 −1 features/support/env.rb
  3. +6 −2 fixedbytm2.rb
  4. +1 −1 models.rb
View
@@ -28,5 +28,14 @@ Feature: Making fun of TextMate 2's long development cycle
When I fill in "text" with "Something Else <strong>STRONG</strong>"
And I press "Suggest it!"
Then I should see "Something Else <strong>STRONG</strong>"
+
+ Scenario: Posting a fix mulitple times
+ When I fill in "text" with "Duke Nukem Forever"
+ And I press "Suggest it!"
+ Then I should be on 4
+ When I fill in "text" with "Duke Nukem Forever"
+ And I press "Suggest it!"
+ Then I should be on 4
+
View
@@ -1,5 +1,5 @@
# Sinatra
-ENVIRONMENT = 'test'
+ENV['RACK_ENV'] = "test"
app_file = File.join(File.dirname(__FILE__), *%w[.. .. fixedbytm2.rb])
require app_file
View
@@ -32,8 +32,12 @@
end
post '/fixes' do
- fix_id = Fix.insert(:text => params[:text], :votes_count => 1)
- FixesUser.insert(:user_id => current_user, :fix_id => fix_id)
+ if fix = Fix.filter(:text => params[:text]).first
+ redirect "/#{fix[:id]}"
+ else
+ fix_id = Fix.insert(:text => params[:text], :votes_count => 1)
+ FixesUser.insert(:user_id => current_user, :fix_id => fix_id)
+ end
redirect "/#{fix_id}"
end
View
@@ -1,4 +1,4 @@
-DB = Sequel.sqlite("fixedbytm2.db")
+DB = ENV['RACK_ENV'] == "test" ? Sequel.sqlite(":memory:") : Sequel.sqlite("fixedbytm2.db")
unless DB.table_exists?(:users)
DB.create_table :users do

0 comments on commit 5ee369b

Please sign in to comment.