Permalink
Browse files

DB is now truncated after each spec.

  • Loading branch information...
aantix committed Jan 9, 2012
1 parent 30383d7 commit 99b6b373d24a46defcda49a3524dcaf8481d6a61
View
@@ -57,6 +57,7 @@ group :test do
#end
gem "rspec"
gem "rspec-rails"
+ gem "rspec-instafail"
gem "guard-rspec"
gem "database_cleaner"
end
View
@@ -156,6 +156,7 @@ GEM
rspec-core (2.7.1)
rspec-expectations (2.7.0)
diff-lcs (~> 1.1.2)
+ rspec-instafail (0.2.2)
rspec-mocks (2.7.0)
rspec-rails (2.7.0)
actionpack (~> 3.0)
@@ -211,6 +212,7 @@ DEPENDENCIES
rails (= 3.1.3)
rb-fsevent (>= 0.4.3.1)
rspec
+ rspec-instafail
rspec-rails
sass-rails
spork (> 0.9.0.rc)
View
@@ -5,10 +5,11 @@ guard 'spork', :cucumber_env => { 'RAILS_ENV' => 'test' }, :rspec_env => { 'RAIL
watch('spec/spec_helper.rb')
end
-guard 'rspec', :version => 2, :cli => "--drb" do
+guard 'rspec', :version => 2, :cli => "--drb -r rspec/instafail -f RSpec::Instafail", :spec_paths => ["spec", "spec/models", "spec/helpers", "spec/controllers", "spec/requests"] do
watch(%r{^spec/.+_spec\.rb$})
- watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
- watch(%r{^app/models/(.+)\.rb$}) { |m| "spec/models/#{m[1]}_spec.rb" }
+ watch(%r{^spec/factories/.+_spec\.rb$})
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
+ watch(%r{^app/models/(.+)\.rb$}) { |m| "spec/models/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { "spec" }
end
View
@@ -18,11 +18,15 @@ The loving individuals of Mechnical Turk and the Rails Turk integration gem, {Tu
* Start the server with 'rails s'
-* Go to {http://localhost:3000}[http://localhost:3000]
+* Go to http://localhost:3000/
There you will see the form that is presented to the Turkers. That is all I have thus far.
+== Requesting Work from the Turkers
+rake turkee:post_hit["https://www.yourapp.com","Please complete our survey","Tell us your favorite color.","Survey",100,0.05,2]
+
+
== Copyright
Copyright (c) 2012 Jim Jones. See LICENSE for details.
View
@@ -3,5 +3,6 @@
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
require File.expand_path('../config/application', __FILE__)
+require 'tasks/turkee'
Politics::Application.load_tasks
@@ -0,0 +1,16 @@
+.candidate{
+ width: 100px;
+ height: 100px;
+ padding: 10px;
+ float: left;
+
+ img{
+ float: left;
+ margin-left: 5px;
+ }
+
+ input{
+ float:left;
+ margin-left: 5px;
+ }
+}
@@ -5,9 +5,4 @@
.transcription_segments_transcription{
width: 500px;
height: 75px;
-}
-
-.candidate{
- width: 100px;
- float: left;
}
View
@@ -5,7 +5,9 @@ class Candidate < ActiveRecord::Base
belongs_to :party
scope :valid, :conditions => {:searchable => true}
+ scope :non_candidates, :conditions => {:searchable => false}
scope :republicans, :conditions => {:party_id => [Party::REPUBLICANS,Party::NA]}
scope :democrats, :conditions => {:party_id => [Party::REPUBLICANS,Party::NA]}
+
end
View
@@ -9,6 +9,10 @@ def self.youtube_video_id(url)
return params["v"][0] if params.has_key?("v")
end
end
+
+ def url
+ "http://www.youtube.com/watch?v=#{video_id}"
+ end
def self.cache_latest
puts "Caching latest videos..."
@@ -24,10 +28,10 @@ def self.cache_latest
def self.cache_search(videos, candidate)
videos.each do |video|
next unless video["embeddable"]
-
+
# Creation will fail if video_id isn't unique
v = Video.create(:title => video["title"],
- :url => video["video_id"],
+ :video_id => video["video_id"],
:description => video["content"],
:published_at => video["published"],
:duration => video["duration"],
@@ -0,0 +1,9 @@
+<div class="span4">
+ <%= f.radio_button :candidate_id, candidate.id, :checked => (candidate == transcription.candidate) %>
+
+ <% if candidate.image? %>
+ <%= image_tag("candidates/#{candidate.image}", :alt => candidate.name, :title => candidate.name) %>
+ <% else %>
+ <%= candidate.name %>
+ <% end %>
+</div>
@@ -20,7 +20,7 @@
</p>
<p>
- For every candidate that speaks, select the "add speaker" button, select who is speaking, and transcribe their text.
+ For every candidate that speaks, select the <span class='btn large success'>add speaker</span> button, select who is speaking, and transcribe their text.
</p>
<p>
@@ -51,11 +51,11 @@
<%= render :partial => 'video', :locals => {:video_segment => @transcription.video_segment} %>
- <div class="alert-message block-message success">
+ <div class="alert-message block-message warning">
<%= f.hidden_field :video_segment_id, :value => @transcription.video_segment.id %>
<p>
- <%= f.link_to_add "Add Speaker", :transcription_segments, :class => 'btn large' %>
+ <%= f.link_to_add "Add Speaker", :transcription_segments, :class => 'btn large success' %>
</p>
<%= f.fields_for :transcription_segments do |segment| %>
@@ -64,14 +64,15 @@
<%= f.label :candidate_id, "Who's speaking?" %>
<div class="input">
- <% @candidates.each do |c| %>
- <div class="candidate">
- <%= image_tag("candidates/#{c.image}", :alt => c.name, :title => c.name) %>
- <%= segment.radio_button :candidate_id, c.id, :checked => (c == @transcription.candidate) %><br/>
- </div>
+ <% @candidates.in_groups_of(4).each do |candidate_group| %>
+ <div class="row">
+ <% candidate_group.each do |c| %>
+ <%= render :partial => 'candidates/candidate',
+ :object => c,
+ :locals => {:f => segment, :transcription => @transcription} %>
+ <% end %>
+ </div>
<% end %>
- <%= segment.radio_button :candidate_id, c.id, :checked => (c == @transcription.candidate) %><br/>
-
</div>
</div>
</div>
@@ -3,13 +3,11 @@ def change
create_table :videos do |t|
t.string :title
t.text :description
- t.string :url, :null => false
t.string :video_id, :null => false
t.datetime :published_at
t.timestamps
end
add_index :videos, :video_id, :unique => true
- add_index :videos, :url, :unique => true
end
end
View
@@ -44,16 +44,6 @@
t.datetime "updated_at"
end
- create_table "sex_it_up_images", :force => true do |t|
- t.string "image_search_term"
- t.string "image_original_url"
- t.string "image_url"
- t.string "image_file_name"
- t.string "image_content_type"
- t.integer "image_file_size"
- t.datetime "image_updated_at"
- end
-
create_table "transcription_segments", :force => true do |t|
t.integer "transcription_id"
t.integer "candidate_id"
@@ -82,7 +72,6 @@
create_table "videos", :force => true do |t|
t.string "title"
t.text "description"
- t.string "url", :null => false
t.string "video_id", :null => false
t.datetime "published_at"
t.datetime "created_at"
@@ -91,7 +80,6 @@
t.integer "candidate_id"
end
- add_index "videos", ["url"], :name => "index_videos_on_url", :unique => true
add_index "videos", ["video_id"], :name => "index_videos_on_video_id", :unique => true
end
View
@@ -4,13 +4,12 @@
Candidate.find_or_create_by_name('Barack Obama'){|c| c.id = 1; c.party_id = 1; c.order = 1; c.image = 'barack_obama.jpg'; c.save}
-newt = Candidate.find_or_create_by_name('Newt Gingrich'){|c| c.id = 2; c.party_id = 2; c.order = 1; c.image = 'newt_gingrich.jpg'; c.save}
-Candidate.find_or_create_by_name('Mitt Romney'){|c| c.id = 3; c.party_id = 2; c.order = 2; c.image = 'mitt_romney.jpg'; c.save}
-Candidate.find_or_create_by_name('Michele Bachmann'){|c| c.id = 4; c.party_id = 2; c.order = 3; c.image = 'michele_bachmann.jpg'; c.save}
-Candidate.find_or_create_by_name('Ron Paul'){|c| c.id = 5; c.party_id = 2; c.order = 4; c.image = 'ron_paul.jpg'; c.save}
-Candidate.find_or_create_by_name('Rick Santorum'){|c| c.id = 6; c.party_id = 2; c.order =5; c.image = 'rick_santorum.jpg'; c.save}
-Candidate.find_or_create_by_name('Rick Perry'){|c| c.id = 7; c.party_id = 2; c.order = 6; c.image = 'rick_perry.jpg'; c.save}
-Candidate.find_or_create_by_name('Jon Huntsman Jr'){|c| c.id = 8; c.party_id = 2; c.order = 7; c.image = 'jon_huntsman.jpg'; c.save}
+Candidate.find_or_create_by_name('Mitt Romney'){|c| c.id = 2; c.party_id = 2; c.order = 2; c.image = 'mitt_romney.jpg'; c.save}
+Candidate.find_or_create_by_name('Rick Santorum'){|c| c.id = 3; c.party_id = 2; c.order =5; c.image = 'rick_santorum.jpg'; c.save}
+Candidate.find_or_create_by_name('Ron Paul'){|c| c.id = 4; c.party_id = 2; c.order = 4; c.image = 'ron_paul.jpg'; c.save}
+newt = Candidate.find_or_create_by_name('Newt Gingrich'){|c| c.id = 5; c.party_id = 2; c.order = 1; c.image = 'newt_gingrich.jpg'; c.save}
+Candidate.find_or_create_by_name('Rick Perry'){|c| c.id = 6; c.party_id = 2; c.order = 6; c.image = 'rick_perry.jpg'; c.save}
+Candidate.find_or_create_by_name('Jon Huntsman Jr'){|c| c.id = 7; c.party_id = 2; c.order = 7; c.image = 'jon_huntsman.jpg'; c.save}
Candidate.find_or_create_by_name('Interviewer'){|c| c.id = 9; c.party_id = 3; c.order = 1; c.searchable = false; c.save}
Candidate.find_or_create_by_name('Nobody\'s Speaking'){|c| c.id = 10; c.party_id = 3; c.order = 2; c.searchable = false; c.save}
@@ -31,19 +30,13 @@
v = Video.find_or_create_by_title('Gingrich: Courts Are Far Too Powerful') do |v|
v.id = 1
v.description = "At the Fox News Presidential Debate in Sioux City, Newt warns activist judges that \"If you keep attacking the core base of the American Exceptionalism you will find an uprising against you which will re-balance the judiciary. We have a balance of three branches, not a judicial dictatorship in this country.\""
- v.url = "http://www.youtube.com/watch?v=YyJNyZSy_NY"
v.video_id = "YyJNyZSy_NY"
v.published_at = Time.now
v.created_at = Time.now
v.updated_at = Time.now
- v.duration = 24
+ v.duration = 125
v.candidate = newt
v.save
end
-VideoSegment.find_or_create_by_video_id(v.id) do |vs|
- vs.id = 1
- vs.offset = 10
- vs.duration = 5
- vs.save
-end
+VideoSegment.partition(v)
View
@@ -6,7 +6,7 @@ def select_items
end
def self.included(base)
- base.scope :all_sorted, :order => :name
+ base.scope :all_sorted, :order => [:id]
base.extend(ClassMethods)
end
end
@@ -2,18 +2,15 @@
s.title "Test Video"
s.video_id "daa9pZDxfIY"
s.description "Test Description"
- s.url "http://www.youtube.com/watch?v=daa9pZDxfIY&feature=g-all-pls"
s.published_at "12-24-2011 12:00:00am"
end
Factory.define :video_60, :parent => :video do |s|
s.video_id "daa9pZDxfIX"
- s.url "http://www.youtube.com/watch?v=daa9pZDxfIX&feature=g-all-pls"
s.duration 60
end
Factory.define :video_95, :parent => :video do |s|
s.video_id "daa9pZDxfIZ"
- s.url "http://www.youtube.com/watch?v=daa9pZDxfIZ&feature=g-all-pls"
s.duration 95
end
View
@@ -3,22 +3,20 @@
describe Video do
describe "#cache_recent" do
- before(:all) do
- Factory.create(:candidate)
- end
-
before(:each) do
@search_results = [{
- "title" => "Killer Whale Imitates Boat Motor",
- "published" => "2011-09-29T15:30:43.000Z",
- "id" => "http://gdata.youtube.com/feeds/api/videos/0b2U5r7Jwkc",
- "video_id" => "0b2U5r7Jwkc",
- "content" => "Top YouTube Videos on ...",
- "updated" => "2011-10-13T20:20:54.000Z",
- "duration" => "90"
+ "title" => "Killer Whale Imitates Boat Motor",
+ "published" => "2011-09-29T15:30:43.000Z",
+ "id" => "http://gdata.youtube.com/feeds/api/videos/0b2U5r7Jwkc",
+ "video_id" => "0b2U5r7Jwkc",
+ "content" => "Top YouTube Videos on ...",
+ "updated" => "2011-10-13T20:20:54.000Z",
+ "duration" => "90",
+ "embeddable" => true
}]
YoutubeSearch.stub!(:search).and_return @search_results
+ Factory.create(:candidate)
end
it "should do a YoutubeSearch for each candidate" do
View
@@ -28,6 +28,21 @@
# config.mock_with :rr
config.mock_with :rspec
+ config.use_transactional_fixtures = false
+
+ config.before(:suite) do
+ DatabaseCleaner.strategy = :truncation
+ DatabaseCleaner.clean_with(:truncation)
+ end
+
+ config.before(:each) do
+ DatabaseCleaner.start
+ end
+
+ config.after(:each) do
+ DatabaseCleaner.clean
+ end
+
#config.before(:suite) do
# DatabaseCleaner.strategy = :transaction
# DatabaseCleaner.clean_with(:truncation)
@@ -46,14 +61,12 @@
# If you're not using ActiveRecord, or you'd prefer not to run each of your
# examples within a transaction, comment the following line or assign false
# instead of true.
- config.use_transactional_fixtures = true
+ #config.use_transactional_fixtures = true
end
end
Spork.each_run do
- # This code will be run each time you run your specs.
- DatabaseCleaner.clean
FactoryGirl.find_definitions
Oops, something went wrong.

0 comments on commit 99b6b37

Please sign in to comment.