octopus 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -10,15 +10,15 @@ begin
10
10
  gem.email = "dave.hrycyszyn@headlondon.com"
11
11
  gem.homepage = "http://github.com/futurechimp/octopus"
12
12
  gem.authors = ["dave@boomer"]
13
- gem.add_dependency "datamapper", ">= 0.10.1"
14
- gem.add_dependency "do_sqlite3", ">= 0.10.0"
15
- gem.add_dependency "sinatra", ">= 0.9.4"
13
+ gem.add_dependency "data_mapper", ">= 1.0.0"
14
+ gem.add_dependency "dm-sqlite-adapter", ">= 1.0.0"
15
+ gem.add_dependency "sinatra", ">= 1.0.0"
16
16
  gem.add_dependency "thin", ">= 1.2.5"
17
17
  gem.add_dependency "rack-flash", ">= 0.1.1"
18
18
  gem.add_dependency "rack", ">= 1.0.1"
19
- gem.add_development_dependency "thoughtbot-shoulda", ">= 2.10.2"
19
+ gem.add_development_dependency "shoulda", ">= 2.10.2"
20
20
  gem.add_development_dependency "rack-test", ">= 0.5.2"
21
- gem.add_development_dependency "notahat-machinist", ">= 1.0.3"
21
+ gem.add_development_dependency "machinist", ">= 1.0.3"
22
22
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
23
23
  end
24
24
  Jeweler::GemcutterTasks.new
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.0.2
data/lib/init.rb CHANGED
@@ -2,11 +2,12 @@
2
2
  #
3
3
  require 'rubygems'
4
4
  require 'sinatra'
5
- require 'datamapper'
5
+ require 'data_mapper'
6
6
  require 'ruby-debug'
7
7
  require 'eventmachine'
8
8
  require 'rack-flash'
9
9
  require 'dm-validations'
10
+ require 'dm-sqlite-adapter'
10
11
 
11
12
 
12
13
  # Extensions to Sinatra
@@ -40,6 +41,9 @@ end
40
41
  configure :production, :test, :development do
41
42
  NetResource.auto_migrate! unless NetResource.storage_exists?
42
43
  Subscription.auto_migrate! unless Subscription.storage_exists?
44
+ end
45
+
46
+ configure :production, :development do
43
47
  DataMapper.auto_upgrade!
44
48
  end
45
49
 
@@ -7,8 +7,6 @@ module Grabbers
7
7
  # starts grabbing expired resources and checking them.
8
8
  #
9
9
  def initialize
10
- @@currently_encoding = false
11
- puts "Initializing generic http grabber..."
12
10
  EM.add_periodic_timer(5) {
13
11
  check_expired_resources
14
12
  }
@@ -5,17 +5,20 @@ class Subscription
5
5
  include DataMapper::Resource
6
6
 
7
7
  # Properties
8
+ #
8
9
  property :id, Serial
9
10
  property :url, String, :required => true, :length => (1..254)
10
11
  property :created_at, DateTime
11
12
  property :updated_at, DateTime
12
13
 
13
14
  # Associations
15
+ #
14
16
  belongs_to :net_resource
15
17
 
16
18
  # Validations
19
+ #
17
20
  validates_with_method :validate_url
18
- validates_present :net_resource
21
+ validates_presence_of :net_resource
19
22
 
20
23
  # Checks that the url property is formatted correctly.
21
24
  #
data/octopus.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{octopus}
8
- s.version = "0.0.1"
8
+ s.version = "0.0.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["dave@boomer"]
12
- s.date = %q{2010-05-13}
12
+ s.date = %q{2010-08-13}
13
13
  s.default_executable = %q{octopus}
14
14
  s.description = %q{Grabs stuff off the net and notifies interested subscribers.}
15
15
  s.email = %q{dave.hrycyszyn@headlondon.com}
@@ -56,6 +56,7 @@ Gem::Specification.new do |s|
56
56
  "octopus.gemspec",
57
57
  "test/helper.rb",
58
58
  "test/support/blueprints.rb",
59
+ "test/test_generic_http_grabber.rb",
59
60
  "test/test_net_resource.rb",
60
61
  "test/test_octopus.rb",
61
62
  "test/test_subscription.rb"
@@ -66,11 +67,12 @@ Gem::Specification.new do |s|
66
67
  s.rubygems_version = %q{1.3.6}
67
68
  s.summary = %q{An experimental octopus implementation.}
68
69
  s.test_files = [
69
- "test/support/blueprints.rb",
70
- "test/test_subscription.rb",
71
- "test/test_net_resource.rb",
70
+ "test/test_net_resource.rb",
72
71
  "test/test_octopus.rb",
73
- "test/helper.rb"
72
+ "test/support/blueprints.rb",
73
+ "test/helper.rb",
74
+ "test/test_generic_http_grabber.rb",
75
+ "test/test_subscription.rb"
74
76
  ]
75
77
 
76
78
  if s.respond_to? :specification_version then
@@ -78,36 +80,36 @@ Gem::Specification.new do |s|
78
80
  s.specification_version = 3
79
81
 
80
82
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
81
- s.add_runtime_dependency(%q<datamapper>, [">= 0.10.1"])
82
- s.add_runtime_dependency(%q<do_sqlite3>, [">= 0.10.0"])
83
- s.add_runtime_dependency(%q<sinatra>, [">= 0.9.4"])
83
+ s.add_runtime_dependency(%q<data_mapper>, [">= 1.0.0"])
84
+ s.add_runtime_dependency(%q<dm-sqlite-adapter>, [">= 1.0.0"])
85
+ s.add_runtime_dependency(%q<sinatra>, [">= 1.0.0"])
84
86
  s.add_runtime_dependency(%q<thin>, [">= 1.2.5"])
85
87
  s.add_runtime_dependency(%q<rack-flash>, [">= 0.1.1"])
86
88
  s.add_runtime_dependency(%q<rack>, [">= 1.0.1"])
87
- s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 2.10.2"])
89
+ s.add_development_dependency(%q<shoulda>, [">= 2.10.2"])
88
90
  s.add_development_dependency(%q<rack-test>, [">= 0.5.2"])
89
- s.add_development_dependency(%q<notahat-machinist>, [">= 1.0.3"])
91
+ s.add_development_dependency(%q<machinist>, [">= 1.0.3"])
90
92
  else
91
- s.add_dependency(%q<datamapper>, [">= 0.10.1"])
92
- s.add_dependency(%q<do_sqlite3>, [">= 0.10.0"])
93
- s.add_dependency(%q<sinatra>, [">= 0.9.4"])
93
+ s.add_dependency(%q<data_mapper>, [">= 1.0.0"])
94
+ s.add_dependency(%q<dm-sqlite-adapter>, [">= 1.0.0"])
95
+ s.add_dependency(%q<sinatra>, [">= 1.0.0"])
94
96
  s.add_dependency(%q<thin>, [">= 1.2.5"])
95
97
  s.add_dependency(%q<rack-flash>, [">= 0.1.1"])
96
98
  s.add_dependency(%q<rack>, [">= 1.0.1"])
97
- s.add_dependency(%q<thoughtbot-shoulda>, [">= 2.10.2"])
99
+ s.add_dependency(%q<shoulda>, [">= 2.10.2"])
98
100
  s.add_dependency(%q<rack-test>, [">= 0.5.2"])
99
- s.add_dependency(%q<notahat-machinist>, [">= 1.0.3"])
101
+ s.add_dependency(%q<machinist>, [">= 1.0.3"])
100
102
  end
101
103
  else
102
- s.add_dependency(%q<datamapper>, [">= 0.10.1"])
103
- s.add_dependency(%q<do_sqlite3>, [">= 0.10.0"])
104
- s.add_dependency(%q<sinatra>, [">= 0.9.4"])
104
+ s.add_dependency(%q<data_mapper>, [">= 1.0.0"])
105
+ s.add_dependency(%q<dm-sqlite-adapter>, [">= 1.0.0"])
106
+ s.add_dependency(%q<sinatra>, [">= 1.0.0"])
105
107
  s.add_dependency(%q<thin>, [">= 1.2.5"])
106
108
  s.add_dependency(%q<rack-flash>, [">= 0.1.1"])
107
109
  s.add_dependency(%q<rack>, [">= 1.0.1"])
108
- s.add_dependency(%q<thoughtbot-shoulda>, [">= 2.10.2"])
110
+ s.add_dependency(%q<shoulda>, [">= 2.10.2"])
109
111
  s.add_dependency(%q<rack-test>, [">= 0.5.2"])
110
- s.add_dependency(%q<notahat-machinist>, [">= 1.0.3"])
112
+ s.add_dependency(%q<machinist>, [">= 1.0.3"])
111
113
  end
112
114
  end
113
115
 
@@ -0,0 +1,9 @@
1
+ require File.dirname(__FILE__) + '/helper'
2
+
3
+ class GenericHttpGrabberTest < Test::Unit::TestCase
4
+
5
+ context "The GenericHttpGrabber" do
6
+ end
7
+
8
+ end
9
+
@@ -55,7 +55,6 @@ class NetResourceTest < Test::Unit::TestCase
55
55
  end
56
56
 
57
57
  context "The NetResource class" do
58
-
59
58
  should "have an 'expired' named scope" do
60
59
  # First, set all existing resources to expire tomorrow and give them a
61
60
  # next_update time of 20 seconds.
data/test/test_octopus.rb CHANGED
@@ -108,40 +108,67 @@ class OctopusTest < Test::Unit::TestCase
108
108
  end
109
109
  end
110
110
 
111
- def test_new_or_edit_for_new_resource
112
- post '/new_or_edit', {:net_resource => {
113
- :url => "http://news.bbc.co.uk/foo/bar/#{DateTime.now.to_s}/blah.rss"
114
- }}, basic_auth_creds
115
- follow_redirect!
116
- assert_equal "http://example.org/new", last_request.url
117
- end
111
+ context "on POST to new_or_edit" do
112
+ context "for a new NetResource" do
113
+ setup do
114
+ post '/new_or_edit', {:net_resource => {
115
+ :url => "http://news.bbc.co.uk/foo/bar/#{DateTime.now.to_s}/blah.rss"
116
+ }}, basic_auth_creds
117
+ follow_redirect!
118
+ end
119
+ should "go to :new action" do
120
+ assert_equal "http://example.org/new", last_request.url
121
+ end
122
+ end
118
123
 
119
- def test_new_or_edit_for_existing_resource
120
- NetResource.make
121
- post '/new_or_edit', {:net_resource => {
122
- :url => NetResource.first.url
123
- }}, basic_auth_creds
124
- follow_redirect!
125
- assert_equal "http://example.org/edit/#{NetResource.first.id}", last_request.url
126
- end
124
+ context "for an existing NetResource" do
125
+ setup do
126
+ NetResource.make
127
+ post '/new_or_edit', {:net_resource => {
128
+ :url => NetResource.first.url
129
+ }}, basic_auth_creds
130
+ follow_redirect!
131
+ end
132
+ should "go to :show action" do
133
+ assert_equal "http://example.org/edit/#{NetResource.first.id}", last_request.url
134
+ end
127
135
 
128
- def test_update
129
- n = NetResource.make
130
- put "/update/#{n.id}", {:id => n.id, :net_resource => {:update_period => 666}}, basic_auth_creds
131
- follow_redirect!
132
- assert_equal "http://example.org/", last_request.url
133
- assert_equal NetResource.first.update_period, 666
136
+ end
134
137
  end
135
138
 
136
- def test_bad_update_redisplays
137
- NetResource.make
138
- NetResource.first.update(:update_period => 60)
139
- put "/update/#{NetResource.first.id}", {:net_resource => {:update_period => 10}}, basic_auth_creds
140
- assert last_response.ok?
141
- assert_equal "http://example.org/update/#{NetResource.first.id}", last_request.url
142
- assert_equal NetResource.first.update_period, 60
139
+ context "on PUT to update" do
140
+ context "with good params" do
141
+ setup do
142
+ n = NetResource.make
143
+ put "/update/#{n.id}", {:id => n.id, :net_resource => {:update_period => 666}}, basic_auth_creds
144
+ follow_redirect!
145
+ should "display /" do
146
+ assert_equal "http://example.org/", last_request.url
147
+ end
148
+ should "set the NetResource's update period" do
149
+ assert_equal NetResource.first.update_period, 666
150
+ end
151
+ end
152
+ end
153
+ context "with bad params" do
154
+ setup do
155
+ NetResource.make
156
+ NetResource.first.update(:update_period => 60)
157
+ put "/update/#{NetResource.first.id}", {:net_resource => {:update_period => 10}}, basic_auth_creds
158
+ end
159
+ should "succeed" do
160
+ assert last_response.ok?
161
+ end
162
+ should "redisplay" do
163
+ assert_equal "http://example.org/update/#{NetResource.first.id}", last_request.url
164
+ end
165
+ should "not set the update period" do
166
+ assert_equal NetResource.first.update_period, 60
167
+ end
168
+ end
143
169
  end
144
170
 
171
+
145
172
  private
146
173
 
147
174
  def clear_database
@@ -5,8 +5,11 @@ class SubscriptionTest < Test::Unit::TestCase
5
5
  context "A Subscription instance" do
6
6
 
7
7
  setup do
8
- @resource = ::NetResource.new(:url => "http://example.org/foo.rss", :update_period => 25)
9
- @resource.subscriptions << Subscription.new(:url => "http://example2.org/callback")
8
+ @resource = ::NetResource.new(
9
+ :url => "http://example.org/foo.rss",
10
+ :update_period => 25)
11
+ @resource.subscriptions << Subscription.new(
12
+ :url => "http://example2.org/callback")
10
13
  @subscription = ::Subscription.new
11
14
  end
12
15
 
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 1
9
- version: 0.0.1
8
+ - 2
9
+ version: 0.0.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - dave@boomer
@@ -14,35 +14,35 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-05-13 00:00:00 +01:00
17
+ date: 2010-08-13 00:00:00 +01:00
18
18
  default_executable: octopus
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
- name: datamapper
21
+ name: data_mapper
22
22
  prerelease: false
23
23
  requirement: &id001 !ruby/object:Gem::Requirement
24
24
  requirements:
25
25
  - - ">="
26
26
  - !ruby/object:Gem::Version
27
27
  segments:
28
- - 0
29
- - 10
30
28
  - 1
31
- version: 0.10.1
29
+ - 0
30
+ - 0
31
+ version: 1.0.0
32
32
  type: :runtime
33
33
  version_requirements: *id001
34
34
  - !ruby/object:Gem::Dependency
35
- name: do_sqlite3
35
+ name: dm-sqlite-adapter
36
36
  prerelease: false
37
37
  requirement: &id002 !ruby/object:Gem::Requirement
38
38
  requirements:
39
39
  - - ">="
40
40
  - !ruby/object:Gem::Version
41
41
  segments:
42
+ - 1
42
43
  - 0
43
- - 10
44
44
  - 0
45
- version: 0.10.0
45
+ version: 1.0.0
46
46
  type: :runtime
47
47
  version_requirements: *id002
48
48
  - !ruby/object:Gem::Dependency
@@ -53,10 +53,10 @@ dependencies:
53
53
  - - ">="
54
54
  - !ruby/object:Gem::Version
55
55
  segments:
56
+ - 1
57
+ - 0
56
58
  - 0
57
- - 9
58
- - 4
59
- version: 0.9.4
59
+ version: 1.0.0
60
60
  type: :runtime
61
61
  version_requirements: *id003
62
62
  - !ruby/object:Gem::Dependency
@@ -102,7 +102,7 @@ dependencies:
102
102
  type: :runtime
103
103
  version_requirements: *id006
104
104
  - !ruby/object:Gem::Dependency
105
- name: thoughtbot-shoulda
105
+ name: shoulda
106
106
  prerelease: false
107
107
  requirement: &id007 !ruby/object:Gem::Requirement
108
108
  requirements:
@@ -130,7 +130,7 @@ dependencies:
130
130
  type: :development
131
131
  version_requirements: *id008
132
132
  - !ruby/object:Gem::Dependency
133
- name: notahat-machinist
133
+ name: machinist
134
134
  prerelease: false
135
135
  requirement: &id009 !ruby/object:Gem::Requirement
136
136
  requirements:
@@ -190,6 +190,7 @@ files:
190
190
  - octopus.gemspec
191
191
  - test/helper.rb
192
192
  - test/support/blueprints.rb
193
+ - test/test_generic_http_grabber.rb
193
194
  - test/test_net_resource.rb
194
195
  - test/test_octopus.rb
195
196
  - test/test_subscription.rb
@@ -224,8 +225,9 @@ signing_key:
224
225
  specification_version: 3
225
226
  summary: An experimental octopus implementation.
226
227
  test_files:
227
- - test/support/blueprints.rb
228
- - test/test_subscription.rb
229
228
  - test/test_net_resource.rb
230
229
  - test/test_octopus.rb
230
+ - test/support/blueprints.rb
231
231
  - test/helper.rb
232
+ - test/test_generic_http_grabber.rb
233
+ - test/test_subscription.rb