delayed-method 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 98dd71101e47e443933ffca6f42c37d945c2f92e
4
+ data.tar.gz: c7c5d3f383502af0d2f0b07330ef6cc6076dbc11
5
+ SHA512:
6
+ metadata.gz: 1eb232ea47d0324d3160e9eb12c5fabeeca457e35c343776054b47d1e5deffbe5de3a14a842e7a0e741ea8c88170140b802010654379726dfed4368b9334afef
7
+ data.tar.gz: 78d815fa211bd1c9a66ac4bff957f36b021a08f5863e5c5e81a77ee6b12040a8401e3440680d81f9cfb5785e4130b7bd15b7e21d85d68367c97cd13a45f8337d
@@ -37,7 +37,7 @@ class DelayedMethod
37
37
  if object.is_a? Class
38
38
  yield object.name, nil
39
39
  elsif object.is_a? ActiveRecord::Base
40
- raise ArgumentError.new("object need to be persisted") unless object.persisted?
40
+ raise ArgumentError.new("object #{object.class}:#{object.id}##{method} needs to be persisted #{caller}") unless object.persisted?
41
41
  yield object.class.name, object.id
42
42
  else
43
43
  raise ArgumentError.new("Only class and ActiveRecord resource are supported")
@@ -28,10 +28,11 @@ describe DelayedMethod do
28
28
  end
29
29
 
30
30
  def mock_armodel
31
- mock(ActiveRecord::Base, { :id => 1, :execute => true, :persisted? => true }).tap do |armodel|
31
+ mock(ActiveRecord::Base, { :id => 1, :execute => true }).tap do |armodel|
32
32
  armodel.should_receive(:is_a?).with(Class).and_return(false)
33
33
  armodel.should_receive(:is_a?).with(ActiveRecord::Base).and_return(true)
34
34
  armodel.should_receive(:class).and_return ActiveRecord::Base
35
+ armodel.stub(:persisted?).and_return true
35
36
  ActiveRecord::Base.stub(:find).with(1).and_return armodel
36
37
  end
37
38
  end
@@ -43,6 +44,17 @@ describe DelayedMethod do
43
44
  klass, args = Resque.reserve(:delayed)
44
45
  klass.perform(*args)
45
46
  end
47
+
48
+ context "object is not persisted" do
49
+ it "raises exception with identifying info" do
50
+ armodel = mock_armodel
51
+ armodel.stub(:some_method)
52
+ armodel.stub(:persisted?).and_return(false)
53
+ expect {
54
+ DelayedMethod.enqueue(armodel, :some_method)
55
+ }.to raise_error(anything, /Base.*some_method/)
56
+ end
57
+ end
46
58
  end
47
59
  end
48
60
  end
data/spec/spec_helper.rb CHANGED
@@ -3,7 +3,3 @@ require 'bundler'
3
3
  require 'rspec'
4
4
  require 'delayed-method'
5
5
  require 'debugger'
6
-
7
- Dir[File.expand_path("../support/*.rb", __FILE__)].each do |file|
8
- require file
9
- end
metadata CHANGED
@@ -1,94 +1,83 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: delayed-method
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
5
- prerelease:
4
+ version: 0.2.1
6
5
  platform: ruby
7
6
  authors:
8
7
  - Phuong Nguyen
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-09-19 00:00:00.000000000 Z
11
+ date: 2016-01-30 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: resque
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - ">="
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - ">="
28
25
  - !ruby/object:Gem::Version
29
26
  version: '0'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: activesupport
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - ">="
36
32
  - !ruby/object:Gem::Version
37
33
  version: '0'
38
34
  type: :runtime
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - ">="
44
39
  - !ruby/object:Gem::Version
45
40
  version: '0'
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: rspec
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ~>
45
+ - - "~>"
52
46
  - !ruby/object:Gem::Version
53
47
  version: '2.0'
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ~>
52
+ - - "~>"
60
53
  - !ruby/object:Gem::Version
61
54
  version: '2.0'
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: debugger
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
- - - ! '>='
59
+ - - ">="
68
60
  - !ruby/object:Gem::Version
69
61
  version: '0'
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
- - - ! '>='
66
+ - - ">="
76
67
  - !ruby/object:Gem::Version
77
68
  version: '0'
78
69
  - !ruby/object:Gem::Dependency
79
70
  name: activerecord
80
71
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
72
  requirements:
83
- - - ! '>='
73
+ - - ">="
84
74
  - !ruby/object:Gem::Version
85
75
  version: '0'
86
76
  type: :development
87
77
  prerelease: false
88
78
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
79
  requirements:
91
- - - ! '>='
80
+ - - ">="
92
81
  - !ruby/object:Gem::Version
93
82
  version: '0'
94
83
  description: Allow you to quickly move a long call to background which then executed
@@ -98,36 +87,34 @@ executables: []
98
87
  extensions: []
99
88
  extra_rdoc_files: []
100
89
  files:
90
+ - LICENSE
101
91
  - README.md
102
92
  - Rakefile
103
- - LICENSE
104
93
  - lib/delayed-method.rb
105
94
  - spec/delayed_method_spec.rb
106
95
  - spec/spec_helper.rb
107
- - spec/support/redis.rb
108
96
  homepage: http://github.com/phuongnd08/delayed-method
109
97
  licenses: []
98
+ metadata: {}
110
99
  post_install_message:
111
100
  rdoc_options: []
112
101
  require_paths:
113
102
  - lib
114
103
  required_ruby_version: !ruby/object:Gem::Requirement
115
- none: false
116
104
  requirements:
117
- - - ! '>='
105
+ - - ">="
118
106
  - !ruby/object:Gem::Version
119
107
  version: '0'
120
108
  required_rubygems_version: !ruby/object:Gem::Requirement
121
- none: false
122
109
  requirements:
123
- - - ! '>='
110
+ - - ">="
124
111
  - !ruby/object:Gem::Version
125
112
  version: '0'
126
113
  requirements: []
127
114
  rubyforge_project:
128
- rubygems_version: 1.8.23
115
+ rubygems_version: 2.2.2
129
116
  signing_key:
130
- specification_version: 3
117
+ specification_version: 4
131
118
  summary: Allow you to quickly move a long call to background which then executed by
132
119
  resque
133
120
  test_files: []
@@ -1,70 +0,0 @@
1
- TMP_PATH = File.expand_path("../../../tmp", __FILE__)
2
- PIDS_PATH = TMP_PATH + "/pids"
3
- REDIS_PID = "#{PIDS_PATH}/redis-test.pid"
4
- REDIS_CACHE_PATH = "#{TMP_PATH}/cache/"
5
-
6
- module RedisHelper
7
- class << self
8
- def start_server
9
- FileUtils.mkdir_p REDIS_CACHE_PATH
10
- FileUtils.mkdir_p PIDS_PATH
11
-
12
- redis_options = {
13
- "daemonize" => 'yes',
14
- "pidfile" => REDIS_PID,
15
- "port" => 9736,
16
- "timeout" => 300,
17
- "save 900" => 1,
18
- "save 300" => 1,
19
- "save 60" => 10000,
20
- "dbfilename" => "dump.rdb",
21
- "dir" => REDIS_CACHE_PATH,
22
- "loglevel" => "debug",
23
- "logfile" => "stdout",
24
- "databases" => 16
25
- }.map { |k, v| "#{k} #{v}" }.join('\n')
26
- `echo '#{redis_options}' | redis-server -`
27
- success = false
28
-
29
- wait_time_remaining = 5
30
- begin
31
- TCPSocket.open("localhost", "9736")
32
- success = true
33
- rescue Exception => e
34
- if wait_time_remaining > 0
35
- wait_time_remaining -= 0.1
36
- sleep 0.1
37
- else
38
- raise "Cannot start redis server in 5 seconds. Pinging server yield\n#{e.inspect}"
39
- end
40
- end while(!success)
41
-
42
- Resque.redis = "localhost:9736"
43
- end
44
-
45
- def stop_server
46
- %x{
47
- cat #{REDIS_PID} | xargs kill -QUIT
48
- rm -f #{REDIS_CACHE_PATH}dump.rdb
49
- }
50
- end
51
-
52
- def clear
53
- Resque.redis.flushdb
54
- end
55
- end
56
- end
57
-
58
- RSpec.configure do |config|
59
- config.before(:each) do
60
- RedisHelper.clear
61
- end
62
-
63
- config.before(:suite) do
64
- RedisHelper.start_server
65
- end
66
-
67
- config.after(:suite) do
68
- RedisHelper.stop_server
69
- end
70
- end