Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Updating specs.

  • Loading branch information...
commit 2a2022784832da40dc309a48dd722a461b142646 1 parent ac532e6
@aantix authored
View
166 Gemfile.lock
@@ -2,109 +2,123 @@ PATH
remote: .
specs:
turkee (1.1.1)
- lockfile (>= 1.4.3)
- rails (>= 3.0.7)
+ lockfile
+ rails (>= 3.1.1)
rturk (>= 2.3.0)
- turkee
GEM
remote: http://rubygems.org/
specs:
- abstract (1.0.0)
- actionmailer (3.0.7)
- actionpack (= 3.0.7)
- mail (~> 2.2.15)
- actionpack (3.0.7)
- activemodel (= 3.0.7)
- activesupport (= 3.0.7)
- builder (~> 2.1.2)
- erubis (~> 2.6.6)
- i18n (~> 0.5.0)
- rack (~> 1.2.1)
- rack-mount (~> 0.6.14)
- rack-test (~> 0.5.7)
- tzinfo (~> 0.3.23)
- activemodel (3.0.7)
- activesupport (= 3.0.7)
- builder (~> 2.1.2)
- i18n (~> 0.5.0)
- activerecord (3.0.7)
- activemodel (= 3.0.7)
- activesupport (= 3.0.7)
- arel (~> 2.0.2)
- tzinfo (~> 0.3.23)
- activeresource (3.0.7)
- activemodel (= 3.0.7)
- activesupport (= 3.0.7)
- activesupport (3.0.7)
- arel (2.0.10)
- builder (2.1.2)
+ actionmailer (3.1.3)
+ actionpack (= 3.1.3)
+ mail (~> 2.3.0)
+ actionpack (3.1.3)
+ activemodel (= 3.1.3)
+ activesupport (= 3.1.3)
+ builder (~> 3.0.0)
+ erubis (~> 2.7.0)
+ i18n (~> 0.6)
+ rack (~> 1.3.5)
+ rack-cache (~> 1.1)
+ rack-mount (~> 0.8.2)
+ rack-test (~> 0.6.1)
+ sprockets (~> 2.0.3)
+ activemodel (3.1.3)
+ activesupport (= 3.1.3)
+ builder (~> 3.0.0)
+ i18n (~> 0.6)
+ activerecord (3.1.3)
+ activemodel (= 3.1.3)
+ activesupport (= 3.1.3)
+ arel (~> 2.2.1)
+ tzinfo (~> 0.3.29)
+ activeresource (3.1.3)
+ activemodel (= 3.1.3)
+ activesupport (= 3.1.3)
+ activesupport (3.1.3)
+ multi_json (~> 1.0)
+ arel (2.2.1)
+ builder (3.0.0)
diff-lcs (1.1.3)
- erubis (2.6.6)
- abstract (>= 1.0.0)
- factory_girl (2.2.0)
+ erubis (2.7.0)
+ factory_girl (2.3.2)
activesupport
- fakeweb (1.3.0)
growl (1.0.3)
guard (0.8.8)
thor (~> 0.14.6)
- guard-rspec (0.5.2)
+ guard-rspec (0.5.9)
guard (>= 0.8.4)
- guard-spork (0.3.1)
+ guard-spork (0.4.1)
guard (>= 0.8.4)
spork (>= 0.8.4)
- i18n (0.5.0)
- lockfile (1.4.3)
- mail (2.2.19)
- activesupport (>= 2.3.6)
+ hike (1.2.1)
+ i18n (0.6.0)
+ json (1.6.3)
+ lockfile (2.1.0)
+ mail (2.3.0)
i18n (>= 0.4.0)
mime-types (~> 1.16)
treetop (~> 1.4.8)
- mime-types (1.16)
- nokogiri (1.4.6)
- polyglot (0.3.1)
- rack (1.2.3)
- rack-mount (0.6.14)
+ metaclass (0.0.1)
+ mime-types (1.17.2)
+ mocha (0.10.0)
+ metaclass (~> 0.0.1)
+ multi_json (1.0.4)
+ nokogiri (1.5.0)
+ polyglot (0.3.3)
+ rack (1.3.5)
+ rack-cache (1.1)
+ rack (>= 0.4)
+ rack-mount (0.8.3)
rack (>= 1.0.0)
- rack-test (0.5.7)
+ rack-ssl (1.3.2)
+ rack
+ rack-test (0.6.1)
rack (>= 1.0)
- rails (3.0.7)
- actionmailer (= 3.0.7)
- actionpack (= 3.0.7)
- activerecord (= 3.0.7)
- activeresource (= 3.0.7)
- activesupport (= 3.0.7)
+ rails (3.1.3)
+ actionmailer (= 3.1.3)
+ actionpack (= 3.1.3)
+ activerecord (= 3.1.3)
+ activeresource (= 3.1.3)
+ activesupport (= 3.1.3)
bundler (~> 1.0)
- railties (= 3.0.7)
- railties (3.0.7)
- actionpack (= 3.0.7)
- activesupport (= 3.0.7)
+ railties (= 3.1.3)
+ railties (3.1.3)
+ actionpack (= 3.1.3)
+ activesupport (= 3.1.3)
+ rack-ssl (~> 1.3.2)
rake (>= 0.8.7)
- thor (~> 0.14.4)
+ rdoc (~> 3.4)
+ thor (~> 0.14.6)
rake (0.9.2.2)
rb-fsevent (0.4.3.1)
- rest-client (1.6.1)
+ rdoc (3.11)
+ json (~> 1.4)
+ rest-client (1.6.7)
mime-types (>= 1.16)
- rspec (2.5.0)
- rspec-core (~> 2.5.0)
- rspec-expectations (~> 2.5.0)
- rspec-mocks (~> 2.5.0)
- rspec-core (2.5.2)
- rspec-expectations (2.5.0)
+ rspec (2.7.0)
+ rspec-core (~> 2.7.0)
+ rspec-expectations (~> 2.7.0)
+ rspec-mocks (~> 2.7.0)
+ rspec-core (2.7.1)
+ rspec-expectations (2.7.0)
diff-lcs (~> 1.1.2)
- rspec-mocks (2.5.0)
- rturk (2.3.5)
- fakeweb
- nokogiri
+ rspec-mocks (2.7.0)
+ rturk (2.5.2)
nokogiri (>= 1.4.1)
- rest-client
rest-client (>= 1.4.0)
- rspec
spork (0.9.0.rc9)
+ sprockets (2.0.3)
+ hike (~> 1.2)
+ rack (~> 1.0)
+ tilt (~> 1.1, != 1.3.0)
+ sqlite3 (1.3.5)
thor (0.14.6)
- treetop (1.4.9)
+ tilt (1.3.3)
+ treetop (1.4.10)
+ polyglot
polyglot (>= 0.3.1)
- tzinfo (0.3.28)
+ tzinfo (0.3.31)
PLATFORMS
ruby
@@ -114,7 +128,9 @@ DEPENDENCIES
growl (>= 1.0.3)
guard-rspec
guard-spork
+ mocha
rb-fsevent (>= 0.4.3.1)
- rspec (= 2.5.0)
+ rspec (>= 2.5.0)
spork (> 0.9.0.rc)
+ sqlite3
turkee!
View
11 Guardfile
@@ -1,4 +1,4 @@
-guard 'spork', :cucumber_env => { 'RAILS_ENV' => 'test' }, :rspec_env => { 'RAILS_ENV' => 'test' } do
+guard 'spork', :rspec_env => { 'RAILS_ENV' => 'test' } do
watch('spec/spec_helper.rb')
end
@@ -7,13 +7,6 @@ guard 'rspec', :version => 2, :cli => "--drb" do
watch(%r{^spec/.+_spec\.rb$})
# lib/
- watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
- watch(%r{^lib/date_time/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
- watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
-
- # lib/
- watch(%r{^normalization/(.+)\.rb$}) { |m| "spec/normalization/#{m[1]}_spec.rb" }
- watch(%r{^transformation/(.+)\.rb$}) { |m| "spec/transformation/#{m[1]}_spec.rb" }
-
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
end
View
28 lib/turkee.rb
@@ -35,10 +35,10 @@ def self.process_hits(turkee_task = nil)
models = []
hit.assignments.each do |assignment|
- next unless assignment_submitted?(assignment)
+ next unless submitted?(assignment.status)
next unless TurkeeImportedAssignment.find_by_assignment_id(assignment.id).nil?
- params = assignment_params(assignment)
+ params = assignment_params(assignment.answers)
param_hash = Rack::Utils.parse_nested_query(params)
model = find_model(param_hash)
@@ -133,14 +133,16 @@ def logger
end
def self.check_hit_completeness(hit, turk, models)
- if hit.completed_assignments == turk.hit_num_assignments
- hit.dispose!
+ mark_completed(hit, models, turk) if hit.completed_assignments == turk.hit_num_assignments
+ end
- turk.complete = true
- turk.save
+ def self.mark_completed(hit, models, turk)
+ hit.dispose!
- models.each{|model| model.hit_complete(turk) if model.respond_to?(:hit_complete)}
- end
+ turk.complete = true
+ turk.save
+
+ models.each { |model| model.hit_complete(turk) if model.respond_to?(:hit_complete) }
end
def self.process_result(assignment, result)
@@ -159,12 +161,12 @@ def self.task_items(turkee_task)
turkee_task.nil? ? TurkeeTask.unprocessed_hits : Array.new << turkee_task
end
- def self.assignment_submitted?(assignment)
- (assignment.status == 'Submitted')
+ def self.submitted?(status)
+ (status == 'Submitted')
end
- def self.assignment_params(assignment)
- assignment.answers.map { |k, v| "#{CGI::escape(k)}=#{CGI::escape(v)}" }.join('&')
+ def self.assignment_params(answers)
+ answers.map { |k, v| "#{CGI::escape(k.to_s)}=#{CGI::escape(v.to_s)}" }.join('&')
end
# Method looks at the parameter and attempts to find an ActiveRecord model
@@ -175,7 +177,7 @@ def self.find_model(param_hash)
param_hash.each do |k, v|
if v.is_a?(Hash)
model = Object::const_get(k.to_s.camelize) rescue next
- return model if model.descends_from_active_record?
+ return model if model.descends_from_active_record? rescue next
end
end
nil
View
14 spec/factories/turkee_task_factory.rb
@@ -0,0 +1,14 @@
+require 'turkee'
+Factory.define :turkee_task, :class => Turkee::TurkeeTask do |s|
+ s.hit_url "http://workersandbox.mturk.com/mturk/preview?groupId=248SVGULF395SZ65OC6S6NYNJDXAO5"
+ s.sandbox true
+ s.task_type "TestTask"
+ s.hit_title "Test Title"
+ s.hit_description "Test Desc"
+ s.hit_id "123"
+ s.hit_reward 0.05
+ s.hit_num_assignments 100
+ s.hit_lifetime 1
+ s.form_url "http://localhost/test_task/new"
+ s.complete true
+end
View
36 spec/spec_helper.rb
@@ -1,12 +1,33 @@
require 'rubygems'
-require "bundler/setup"
+require "bundler/setup"
-# require File.expand_path("../../config/environment", __FILE__)
require 'factory_girl'
require 'rspec'
require 'spork'
require 'growl'
-
+require 'rails'
+require 'rturk'
+require 'lockfile'
+require 'active_record'
+
+ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
+ActiveRecord::Schema.define(:version => 1) do
+ create_table :turkee_tasks do |t|
+ t.string "hit_url"
+ t.boolean "sandbox"
+ t.string "task_type"
+ t.text "hit_title"
+ t.text "hit_description"
+ t.string "hit_id"
+ t.decimal "hit_reward", :precision => 10, :scale => 2
+ t.integer "hit_num_assignments"
+ t.integer "hit_lifetime"
+ t.string "form_url"
+ t.boolean "complete"
+ end
+end
+
+
Spork.prefork do
# Loading more in this block will cause your tests to run faster. However,
# if you change any configuration or code from libraries loaded here, you'll
@@ -35,11 +56,6 @@
end
Spork.each_run do
- # This code will be run each time you run your specs.
- Dir["#{File.dirname(__FILE__)}/../lib/**/*.rb"].each {|f| require f}
- Dir["#{File.dirname(__FILE__)}/../lib/date_time/**/*.rb"].each {|f| require f}
-
- Dir["#{File.dirname(__FILE__)}/factories/**/*.rb"].each {|f| require f}
- Dir["#{File.dirname(__FILE__)}/../normalization/**/*.rb"].each {|f| require f}
- Dir["#{File.dirname(__FILE__)}/../transformation/**/*.rb"].each {|f| require f}
+ $LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib')
+ Dir["#{File.dirname(__FILE__)}/../lib/**/*.rb"].each {|f| puts "f = #{f}"; require f}
end
View
47 spec/turkee_spec.rb
@@ -1,7 +1,46 @@
-require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
+require 'spec_helper'
-describe "Turkee" do
- it "fails" do
- fail "hey buddy, you should probably rename this file and start specing for real"
+
+describe Turkee::TurkeeTask do
+ #include ActionController::Routing::Routes
+ class TestTask < ActiveRecord::Base
+ def self.abstract_class; true; end
+ attr_accessor :description
+ end
+
+ describe "#process_hits" do
+ before(:each) do
+
+ end
+
+ end
+
+
+ describe "#find_model" do
+
+ it "should return a turkee_task mode " do
+ returned_data = {:submit => 'Create', "test_task" => {:description => "desc"}}
+ Turkee::TurkeeTask.find_model(returned_data).should == TestTask
+ end
+
+ it "should return a nil" do
+ returned_data = {:submit => 'Create', "another_task_class" => {:description => "desc"}}
+ Turkee::TurkeeTask.find_model(returned_data).should be_nil
+ end
+
+ end
+
+ describe "#assignment_params" do
+ it "should encode the params properly" do
+ answers = {:test => "abc", :test2 => "this is a test"}
+ Turkee::TurkeeTask.assignment_params(answers).should == "test=abc&test2=this+is+a+test"
+ end
+ end
+
+ describe "#submitted" do
+ it "should return true for a submitted status" do
+ Turkee::TurkeeTask.submitted?("Submitted").should == true
+ end
end
+
end
View
9 turkee.gemspec
@@ -49,15 +49,16 @@ Gem::Specification.new do |s|
s.rubygems_version = %q{1.8.1}
s.summary = %q{Turkee makes dealing with Amazon's Mechnical Turk a breeze.}
- s.add_dependency(%q<turkee>, [">= 0"])
- s.add_dependency(%q<rails>, [">= 3.0.7"])
+ s.add_dependency(%q<lockfile>)
+ s.add_dependency(%q<rails>, [">= 3.1.1"])
s.add_dependency(%q<rturk>, [">= 2.3.0"])
- s.add_dependency(%q<lockfile>, [">= 1.4.3"])
s.add_development_dependency "guard-rspec"
s.add_development_dependency "spork", "> 0.9.0.rc"
s.add_development_dependency 'growl', '>= 1.0.3'
s.add_development_dependency "guard-spork"
+ s.add_development_dependency "mocha"
+ s.add_development_dependency "sqlite3"
# Since Growl is Mac OS X the `if` test only installs those gems for the development profile on OS X
if RUBY_PLATFORM.downcase.include?("darwin")
@@ -67,6 +68,6 @@ Gem::Specification.new do |s|
# RSpec has to be in both test and development so that rake tasks and generators
# are available without having to explicitly switch the environment to 'test'
s.add_development_dependency 'factory_girl', '>= 1.3.2'
- s.add_development_dependency 'rspec', '= 2.5.0'
+ s.add_development_dependency 'rspec', '>= 2.5.0'
end
Please sign in to comment.
Something went wrong with that request. Please try again.