navvy-sequelhooks 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ describe Navvy::Logger do
4
+ describe '#colorized_info' do
5
+ describe 'when logging to STDOUT' do
6
+ it 'should use the provided colors' do
7
+ logger = Navvy::Logger.new
8
+ logger.should_not_receive(:info).with('colors!')
9
+ logger.should_receive(:info).with("\e[32mcolors!\e[0m")
10
+ logger.colorized_info 'colors!', 32
11
+ end
12
+ end
13
+
14
+ describe 'when logging to a file' do
15
+ it 'should not use the provided colors' do
16
+ logger = Navvy::Logger.new('/dev/null')
17
+ logger.should_receive(:info).with('colors!')
18
+ logger.should_not_receive(:info).with("\e[32mcolors!\e[0m")
19
+ logger.colorized_info 'colors!', 32
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,20 @@
1
+ require 'navvy/job/active_record'
2
+
3
+ ActiveRecord::Base.establish_connection(:adapter => 'sqlite3', :database => '/tmp/navvy_test.sqlite')
4
+
5
+ ActiveRecord::Schema.define do
6
+ create_table :jobs, :force => true do |table|
7
+ table.string :object
8
+ table.string :method_name
9
+ table.text :arguments
10
+ table.integer :priority, :default => 0
11
+ table.string :return
12
+ table.string :exception
13
+ table.integer :parent_id
14
+ table.datetime :created_at
15
+ table.datetime :run_at
16
+ table.datetime :started_at
17
+ table.datetime :completed_at
18
+ table.datetime :failed_at
19
+ end
20
+ end
@@ -0,0 +1,4 @@
1
+ require 'navvy/job/data_mapper'
2
+ DataMapper.setup(:default, "sqlite3:///tmp/navvy_test.sqlite")
3
+ DataMapper.finalize
4
+ Navvy::Job.auto_migrate!
@@ -0,0 +1,2 @@
1
+ require 'navvy/job/mongo_mapper'
2
+ MongoMapper.database = 'navvy_test'
@@ -0,0 +1,9 @@
1
+ require 'mongoid'
2
+
3
+ Mongoid.configure do |config|
4
+ name = "navvy_test"
5
+ config.allow_dynamic_fields = false
6
+ config.master = Mongo::Connection.new.db(name)
7
+ end
8
+
9
+ require 'navvy/job/mongoid'
@@ -0,0 +1,21 @@
1
+ require 'sequel'
2
+
3
+ Sequel.sqlite('/tmp/navvy_test.sqlite')
4
+
5
+ Sequel::DATABASES[0].create_table!(:jobs) do
6
+ primary_key :id, :type => Integer
7
+ String :object
8
+ String :method_name
9
+ String :arguments, :text => true
10
+ Integer :priority, :default => 0
11
+ String :return
12
+ String :exception
13
+ Integer :parent_id
14
+ DateTime :created_at
15
+ DateTime :run_at
16
+ DateTime :started_at
17
+ DateTime :completed_at
18
+ DateTime :failed_at
19
+ end
20
+
21
+ require 'navvy/job/sequel'
@@ -0,0 +1,21 @@
1
+ require 'sequel'
2
+
3
+ Sequel.sqlite('/tmp/navvy_test.sqlite')
4
+
5
+ Sequel::DATABASES[0].create_table!(:jobs) do
6
+ primary_key :id, :type => Integer
7
+ String :object
8
+ String :method_name
9
+ String :arguments, :text => true
10
+ Integer :priority, :default => 0
11
+ String :return
12
+ String :exception
13
+ Integer :parent_id
14
+ DateTime :created_at
15
+ DateTime :run_at
16
+ DateTime :started_at
17
+ DateTime :completed_at
18
+ DateTime :failed_at
19
+ end
20
+
21
+ require 'navvy/job/sequelhooks'
@@ -0,0 +1,39 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'navvy'
4
+ require 'rspec'
5
+ require 'timecop'
6
+
7
+ def job_count
8
+ if defined? Navvy::Job.count
9
+ Navvy::Job.count
10
+ else
11
+ Navvy::Job.all.length
12
+ end
13
+ end
14
+
15
+ def first_job
16
+ Navvy::Job.first
17
+ end
18
+
19
+ class Cow
20
+ def self.speak
21
+ 'moo'
22
+ end
23
+
24
+ def self.broken
25
+ raise 'this method is broken'
26
+ end
27
+ end
28
+
29
+ module Animals
30
+ class Cow
31
+ def self.speak
32
+ 'moo'
33
+ end
34
+
35
+ def self.broken
36
+ raise 'this method is broken'
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ describe Navvy::Worker do
4
+ describe '.fetch_and_run_jobs' do
5
+ before do
6
+ @jobs = [
7
+ Navvy::Job.enqueue(Cow, :speak),
8
+ Navvy::Job.enqueue(Cow, :speak),
9
+ Navvy::Job.enqueue(Cow, :speak)
10
+ ]
11
+
12
+ Navvy::Job.stub!(:next).and_return(@jobs)
13
+ end
14
+
15
+ it 'should fetch jobs' do
16
+ Navvy::Job.should_receive(:next).and_return(@jobs)
17
+ Navvy::Worker.fetch_and_run_jobs
18
+ end
19
+
20
+ it 'should run three jobs' do
21
+ @jobs.each do |job|
22
+ job.should_receive(:run)
23
+ end
24
+ Navvy::Worker.fetch_and_run_jobs
25
+ end
26
+ end
27
+ end
data/spec/zhooks.rb ADDED
@@ -0,0 +1,47 @@
1
+ # Sorry for the naming, otherwise rspec executes this file too early
2
+
3
+ require "spec_helper"
4
+ require "date"
5
+
6
+ # extend class Job
7
+ module SequelHooks
8
+ module InstanceMethods
9
+ def before_create
10
+ puts "Job is created"
11
+ end
12
+
13
+ def after_update
14
+ puts "Job is updated"
15
+ end
16
+
17
+ def after_destroy
18
+ puts "Job is gone"
19
+ end
20
+ end
21
+ end
22
+
23
+ Navvy::Job.plugin( SequelHooks )
24
+
25
+ # test
26
+
27
+ describe "when Job is created" do
28
+ it "should output that it's created" do
29
+ Navvy::Job.enqueue( Cow, :speak)
30
+ end
31
+ end
32
+
33
+ describe "when Job is updated" do
34
+ it "should output that it's updated" do
35
+ Navvy::Job.enqueue( Cow, :speak )
36
+ job = first_job
37
+ job.failed_at = DateTime.now
38
+ end
39
+ end
40
+
41
+ describe "when job is destroyed" do
42
+ it "should output that it's destroyed" do
43
+ Navvy::Job.enqueue( Cow, :speak )
44
+ job = first_job
45
+ job.destroy
46
+ end
47
+ end
metadata ADDED
@@ -0,0 +1,160 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: navvy-sequelhooks
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.3.3
6
+ platform: ruby
7
+ authors:
8
+ - Jeff Kreeftmeijer
9
+ - Nikolaus Piccolotto
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+
14
+ date: 2013-01-23 00:00:00 Z
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: rake
18
+ prerelease: false
19
+ requirement: &id001 !ruby/object:Gem::Requirement
20
+ none: false
21
+ requirements:
22
+ - - ">="
23
+ - !ruby/object:Gem::Version
24
+ version: "0"
25
+ type: :development
26
+ version_requirements: *id001
27
+ - !ruby/object:Gem::Dependency
28
+ name: sqlite3
29
+ prerelease: false
30
+ requirement: &id002 !ruby/object:Gem::Requirement
31
+ none: false
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: "0"
36
+ type: :development
37
+ version_requirements: *id002
38
+ - !ruby/object:Gem::Dependency
39
+ name: bson_ext
40
+ prerelease: false
41
+ requirement: &id003 !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: "0"
47
+ type: :development
48
+ version_requirements: *id003
49
+ - !ruby/object:Gem::Dependency
50
+ name: rspec
51
+ prerelease: false
52
+ requirement: &id004 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ~>
56
+ - !ruby/object:Gem::Version
57
+ version: "2"
58
+ type: :development
59
+ version_requirements: *id004
60
+ - !ruby/object:Gem::Dependency
61
+ name: yard
62
+ prerelease: false
63
+ requirement: &id005 !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: 0.5.2
69
+ type: :development
70
+ version_requirements: *id005
71
+ - !ruby/object:Gem::Dependency
72
+ name: timecop
73
+ prerelease: false
74
+ requirement: &id006 !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: 0.3.5
80
+ type: :development
81
+ version_requirements: *id006
82
+ - !ruby/object:Gem::Dependency
83
+ name: fuubar
84
+ prerelease: false
85
+ requirement: &id007 !ruby/object:Gem::Requirement
86
+ none: false
87
+ requirements:
88
+ - - ~>
89
+ - !ruby/object:Gem::Version
90
+ version: "0.0"
91
+ type: :development
92
+ version_requirements: *id007
93
+ description: Simple background job processor inspired by delayed_job, but aiming for database agnosticism.
94
+ email: nikolaus.piccolotto@gmail.com
95
+ executables: []
96
+
97
+ extensions: []
98
+
99
+ extra_rdoc_files: []
100
+
101
+ files:
102
+ - generators/navvy/navvy_generator.rb
103
+ - generators/navvy/templates/active_record_migration.rb
104
+ - generators/navvy/templates/sequel_migration.rb
105
+ - lib/generators/navvy_generator.rb
106
+ - lib/navvy/configuration.rb
107
+ - lib/navvy/job/active_record.rb
108
+ - lib/navvy/job/data_mapper.rb
109
+ - lib/navvy/job/mongo_mapper.rb
110
+ - lib/navvy/job/mongoid.rb
111
+ - lib/navvy/job/sequel.rb
112
+ - lib/navvy/job/sequelhooks.rb
113
+ - lib/navvy/job.rb
114
+ - lib/navvy/logger.rb
115
+ - lib/navvy/tasks.rb
116
+ - lib/navvy/worker.rb
117
+ - lib/navvy.rb
118
+ - spec/configuration_spec.rb
119
+ - spec/job_spec.rb
120
+ - spec/logger_spec.rb
121
+ - spec/setup/active_record.rb
122
+ - spec/setup/data_mapper.rb
123
+ - spec/setup/mongo_mapper.rb
124
+ - spec/setup/mongoid.rb
125
+ - spec/setup/sequel.rb
126
+ - spec/setup/sequelhooks.rb
127
+ - spec/spec_helper.rb
128
+ - spec/worker_spec.rb
129
+ - spec/zhooks.rb
130
+ - README.textile
131
+ - LICENSE
132
+ homepage: http://github.com/prayerslayer/navvy
133
+ licenses: []
134
+
135
+ post_install_message:
136
+ rdoc_options: []
137
+
138
+ require_paths:
139
+ - lib
140
+ required_ruby_version: !ruby/object:Gem::Requirement
141
+ none: false
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: "0"
146
+ required_rubygems_version: !ruby/object:Gem::Requirement
147
+ none: false
148
+ requirements:
149
+ - - ">="
150
+ - !ruby/object:Gem::Version
151
+ version: "0"
152
+ requirements: []
153
+
154
+ rubyforge_project:
155
+ rubygems_version: 1.8.24
156
+ signing_key:
157
+ specification_version: 3
158
+ summary: Simple background job processor inspired by delayed_job, but aiming for database agnosticism.
159
+ test_files: []
160
+