Skip to content

Commit

Permalink
Replace Machinist with FactoryGirl
Browse files Browse the repository at this point in the history
  • Loading branch information
knowtheory committed May 11, 2017
1 parent 4f4f187 commit 5325629
Show file tree
Hide file tree
Showing 10 changed files with 70 additions and 29 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ group :test do
gem "rack-test", :require => "rack/test"
gem 'sham'
gem 'machinist'
gem "factory_girl_rails", "~> 4.0"
end

13 changes: 13 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ GEM
unf (>= 0.0.5, < 1.0.0)
erubi (1.6.0)
eventmachine (1.2.3)
factory_girl (4.8.0)
activesupport (>= 3.0.0)
factory_girl_rails (4.8.0)
factory_girl (~> 4.8.0)
railties (>= 3.0.0)
faker (1.7.3)
i18n (~> 0.5)
http-cookie (1.0.3)
Expand Down Expand Up @@ -91,6 +96,12 @@ GEM
nokogiri (>= 1.6)
rails-html-sanitizer (1.0.3)
loofah (~> 2.0)
railties (5.1.0)
actionpack (= 5.1.0)
activesupport (= 5.1.0)
method_source
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)
rake (12.0.0)
rest-client (2.0.2)
http-cookie (>= 1.0.2, < 2.0)
Expand All @@ -114,6 +125,7 @@ GEM
daemons (~> 1.0, >= 1.0.9)
eventmachine (~> 1.0, >= 1.0.4)
rack (>= 1, < 3)
thor (0.19.4)
thread_safe (0.3.6)
tilt (2.0.7)
tzinfo (1.2.3)
Expand All @@ -129,6 +141,7 @@ DEPENDENCIES
activesupport
byebug
cloud-crowd!
factory_girl_rails (~> 4.0)
faker
machinist
mocha (>= 0.9.7)
Expand Down
2 changes: 1 addition & 1 deletion test/acceptance/test_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def app
WorkUnit.stubs(:distribute_to_nodes).returns([])
Dispatcher.any_instance.stubs(:distribute_periodically)
Job.destroy_all
2.times { Job.make! }
2.times { create(:job) }
end


Expand Down
66 changes: 46 additions & 20 deletions test/blueprints.rb
Original file line number Diff line number Diff line change
@@ -1,22 +1,48 @@
CloudCrowd::Job.blueprint do
status { CloudCrowd::PROCESSING }
inputs { ['http://www.google.com/intl/en_ALL/images/logo.gif'].to_json }
action { 'graphics_magick' }
options { {}.to_json }
email { 'noone@example.com' }
end
# CloudCrowd::Job.blueprint do
# status { CloudCrowd::PROCESSING }
# inputs { ['http://www.google.com/intl/en_ALL/images/logo.gif'].to_json }
# action { 'graphics_magick' }
# options { {}.to_json }
# email { 'noone@example.com' }
# end
#
# CloudCrowd::NodeRecord.blueprint do
# host { "hostname-#{sn}" }
# ip_address { '127.0.0.1' }
# port { 6093 }
# enabled_actions { 'graphics_magick,word_count' }
# max_workers { 3 }
# end
#
# CloudCrowd::WorkUnit.blueprint do
# job { CloudCrowd::Job.make! }
# status { CloudCrowd::PROCESSING }
# input { '{"key":"value"}' }
# action { 'graphics_magick' }
# end

CloudCrowd::NodeRecord.blueprint do
host { "hostname-#{sn}" }
ip_address { '127.0.0.1' }
port { 6093 }
enabled_actions { 'graphics_magick,word_count' }
max_workers { 3 }
FactoryGirl.define do
factory :job, class: CloudCrowd::Job do
status CloudCrowd::PROCESSING
inputs { ['http://www.google.com/intl/en_ALL/images/logo.gif'].to_json }
action 'graphics_magick'
options { {}.to_json }
email 'noone@example.com'
end

factory :node_record, class: CloudCrowd::NodeRecord do
sequence(:host){ |sn| "hostname-#{sn}" }
ip_address '127.0.0.1'
port 6093
enabled_actions 'graphics_magick,word_count'
max_workers 3
end

factory :work_unit, class: CloudCrowd::WorkUnit do
association :job, factory: :job

status CloudCrowd::PROCESSING
input '{"key":"value"}'
action 'graphics_magick'
end
end

CloudCrowd::WorkUnit.blueprint do
job { CloudCrowd::Job.make! }
status { CloudCrowd::PROCESSING }
input { '{"key":"value"}' }
action { 'graphics_magick' }
end
3 changes: 2 additions & 1 deletion test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
require 'machinist/active_record'
require 'mocha/setup'
require 'byebug'
require 'factory_girl'

here = File.dirname(__FILE__)
require File.expand_path(here + "/../lib/cloud-crowd")
Expand All @@ -20,7 +21,6 @@

require "#{CloudCrowd::ROOT}/test/blueprints.rb"


module TestHelpers
def setup
CloudCrowd::WorkUnit.stubs(:distribute_to_nodes).returns([])
Expand All @@ -36,6 +36,7 @@ def teardown

class Minitest::Test
include TestHelpers
include FactoryGirl::Syntax::Methods
include Shoulda::Matchers::ActiveRecord
extend Shoulda::Matchers::ActiveRecord
include Shoulda::Matchers::ActiveModel
Expand Down
2 changes: 1 addition & 1 deletion test/unit/test_black_listed_action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class BlackListedActionTest < Minitest::Test
setup do
BlackListedAction.destroy_all
@black_listed_action = BlackListedAction.create(action: 'word_count')
@node = NodeRecord.make!
@node = create(:node_record)
end

teardown do
Expand Down
2 changes: 1 addition & 1 deletion test/unit/test_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class JobTest < Minitest::Test
context "A CloudCrowd Job" do

setup do
@job = Job.make!
@job = create(:job)
@unit = @job.work_units.first
end

Expand Down
4 changes: 2 additions & 2 deletions test/unit/test_node_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class NodeRecordTest < Minitest::Test
context "A NodeRecord" do

setup do
@node = CloudCrowd::NodeRecord.make!
@node = create(:node_record)
end

subject { @node }
Expand All @@ -28,7 +28,7 @@ class NodeRecordTest < Minitest::Test
should "know if the node is busy" do
assert !@node.busy?
assert @node.display_status == 'available'
(@node.max_workers + 1).times { WorkUnit.make!(:node_record => @node) }
(@node.max_workers + 1).times { create(:work_unit, node_record: @node ) }
assert @node.busy?
assert @node.display_status == 'busy'
@node.release_work_units
Expand Down
4 changes: 2 additions & 2 deletions test/unit/test_work_unit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class WorkUnitTest < Minitest::Test
context "A WorkUnit" do

setup do
@unit = CloudCrowd::WorkUnit.make!
@unit = create(:work_unit)
@job = @unit.job
end

Expand All @@ -26,7 +26,7 @@ class WorkUnitTest < Minitest::Test
end

should "have JSON that includes job attributes" do
job = Job.make!
job = create(:job)
unit_data = JSON.parse(job.work_units.first.to_json)
assert unit_data['job_id'] == job.id
assert unit_data['action'] == job.action
Expand Down
2 changes: 1 addition & 1 deletion test/unit/test_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class WorkerTest < Minitest::Test

setup do
@node = Node.new.instance_variable_get(:"@instance")
@unit = WorkUnit.make!
@unit = create(:work_unit)
@worker = Worker.new(@node, JSON.parse(@unit.to_json))
end

Expand Down

0 comments on commit 5325629

Please sign in to comment.