octopus 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. data/.document +5 -0
  2. data/.gitignore +22 -0
  3. data/LICENSE +20 -0
  4. data/README.rdoc +41 -0
  5. data/Rakefile +62 -0
  6. data/VERSION +1 -0
  7. data/bin/octopus +16 -0
  8. data/doc/octopus.zargo +0 -0
  9. data/lib/ext/array_ext.rb +8 -0
  10. data/lib/ext/partials.rb +27 -0
  11. data/lib/ext/reloader.rb +11 -0
  12. data/lib/init.rb +68 -0
  13. data/lib/octopus/config.ru +11 -0
  14. data/lib/octopus/grabbers/generic_http.rb +75 -0
  15. data/lib/octopus/models/net_resource.rb +68 -0
  16. data/lib/octopus/models/subscription.rb +35 -0
  17. data/lib/octopus/public/default.css +233 -0
  18. data/lib/octopus/public/images/bg01.jpg +0 -0
  19. data/lib/octopus/public/images/bg02.jpg +0 -0
  20. data/lib/octopus/public/images/bg03.jpg +0 -0
  21. data/lib/octopus/public/images/bg04.jpg +0 -0
  22. data/lib/octopus/public/images/img01.jpg +0 -0
  23. data/lib/octopus/public/images/img02.gif +0 -0
  24. data/lib/octopus/public/images/img03.gif +0 -0
  25. data/lib/octopus/public/images/img04.gif +0 -0
  26. data/lib/octopus/public/images/img05.gif +0 -0
  27. data/lib/octopus/public/images/img06.jpg +0 -0
  28. data/lib/octopus/public/images/spacer.gif +0 -0
  29. data/lib/octopus/views/edit.erb +29 -0
  30. data/lib/octopus/views/index.erb +21 -0
  31. data/lib/octopus/views/layout.erb +65 -0
  32. data/lib/octopus/views/new.erb +42 -0
  33. data/lib/octopus/views/resource_list_item.erb +9 -0
  34. data/lib/octopus.rb +81 -0
  35. data/octopus.gemspec +113 -0
  36. data/test/helper.rb +50 -0
  37. data/test/support/blueprints.rb +20 -0
  38. data/test/test_net_resource.rb +79 -0
  39. data/test/test_octopus.rb +153 -0
  40. data/test/test_subscription.rb +45 -0
  41. metadata +231 -0
@@ -0,0 +1,79 @@
1
+ require File.dirname(__FILE__) + '/helper'
2
+
3
+ class NetResourceTest < Test::Unit::TestCase
4
+
5
+ context "A NetResource instance" do
6
+
7
+ should "validate the url" do
8
+ resource = ::NetResource.new
9
+ assert !resource.valid?
10
+ resource.url = "http://foo.com/blah.rss"
11
+ assert resource.valid?
12
+ resource.url = "foo"
13
+ assert !resource.valid?
14
+ end
15
+
16
+ should "have a working subscription association" do
17
+ resource = ::NetResource.new
18
+ assert resource.respond_to?("subscriptions")
19
+ subscription = ::Subscription.new(:url => "http://example.org/notify")
20
+ assert_nothing_raised do
21
+ resource.subscriptions << subscription
22
+ end
23
+ assert_equal resource.subscriptions.first, subscription
24
+ end
25
+
26
+ should "not have an update period less than twenty seconds" do
27
+ resource = ::NetResource.new(:url => "http://foo.bar.org")
28
+ resource.update_period = 19
29
+ assert !resource.valid?
30
+ resource.update_period = 20
31
+ assert resource.valid?
32
+ end
33
+
34
+ should "set its update period" do
35
+ resource = ::NetResource.new(:url => "http://foo.bar.org")
36
+ resource.update_period = nil
37
+ assert !resource.valid?
38
+ end
39
+
40
+ should "have a next_update method" do
41
+ resource = NetResource.new
42
+ assert resource.respond_to?("set_next_update")
43
+ end
44
+
45
+ should "be able to set its next update period correctly" do
46
+ resource = ::NetResource.new(:url => "http://foo.bar.org")
47
+ resource.save!
48
+ resource.set_next_update
49
+ assert_equal Time.parse(resource.next_update.to_s), Time.parse((Time.now + resource.update_period).to_s)
50
+ end
51
+
52
+ should "have an 'expired' method" do
53
+ assert ::NetResource.respond_to?("expired")
54
+ end
55
+ end
56
+
57
+ context "The NetResource class" do
58
+
59
+ should "have an 'expired' named scope" do
60
+ # First, set all existing resources to expire tomorrow and give them a
61
+ # next_update time of 20 seconds.
62
+ ::NetResource.all.each do |resource|
63
+ resource.next_update = Time.now + 24*60*60
64
+ resource.update_period = 20
65
+ resource.save!
66
+ end
67
+ assert_equal 0, ::NetResource.expired.length
68
+
69
+ resource = ::NetResource.new(:url => "http://foo.bar.org")
70
+ resource.update_period = 20
71
+ resource.next_update = Time.now - 25
72
+ resource.save!
73
+ assert_equal 1, ::NetResource.expired.length
74
+ resource.set_next_update
75
+ assert_equal 0, ::NetResource.expired.length
76
+ end
77
+ end
78
+ end
79
+
@@ -0,0 +1,153 @@
1
+ require File.dirname(__FILE__) + '/helper'
2
+
3
+ class OctopusTest < Test::Unit::TestCase
4
+
5
+ def setup
6
+ clear_database
7
+ end
8
+
9
+ context "on GET to / without credentials" do
10
+ setup do
11
+ get '/'
12
+ end
13
+
14
+ should "respond" do
15
+ assert !last_response.ok?
16
+ assert_equal 401, status
17
+ end
18
+ end
19
+
20
+ context "on GET to / with credentials" do
21
+ setup do
22
+ get '/', {}, basic_auth_creds
23
+ end
24
+
25
+ should "respond" do
26
+ assert last_response.ok?
27
+ end
28
+
29
+ context "when there is one NetResource" do
30
+ setup do
31
+ NetResource.make
32
+ get '/', {}, basic_auth_creds
33
+ end
34
+
35
+ should "work" do
36
+ assert last_response.ok?
37
+ end
38
+ end
39
+ end
40
+
41
+ context "on GET to /new with credentials" do
42
+ setup do
43
+ get '/new', {}, basic_auth_creds
44
+ end
45
+
46
+ should "respond" do
47
+ assert last_response.ok?
48
+ end
49
+ end
50
+
51
+ context "on GET to /edit with credentials" do
52
+ setup do
53
+ n = NetResource.make
54
+ get "/edit/#{n.id}", {}, basic_auth_creds
55
+ end
56
+
57
+ should "respond" do
58
+ assert last_response.ok?
59
+ end
60
+ end
61
+
62
+ context "POST to create" do
63
+ num_resources = NetResource.count
64
+ num_subscriptions = Subscription.count
65
+ n = NetResource.plan
66
+ s = Subscription.plan
67
+
68
+ context "without credentials" do
69
+ setup do
70
+ post '/create', {:net_resource => n, :subscription => s}
71
+ end
72
+ should "respond with a 401 unauthorized" do
73
+ assert !last_response.ok?
74
+ assert_equal 401, status
75
+ end
76
+ end
77
+
78
+ context "with a valid new NetResource" do
79
+ setup do
80
+ num_resources = NetResource.count
81
+ num_subscriptions = Subscription.count
82
+ post '/create', {:net_resource => NetResource.plan, :subscription => Subscription.plan}, basic_auth_creds
83
+ follow_redirect!
84
+ end
85
+
86
+ should "redirect" do
87
+ assert_equal "http://example.org/", last_request.url
88
+ assert_equal num_resources + 1, NetResource.count
89
+ assert_equal num_subscriptions + 1, Subscription.count
90
+ end
91
+ end
92
+
93
+ context "for an existing NetResource" do
94
+ setup do
95
+ n = NetResource.make
96
+ s = Subscription.plan
97
+ num_resources = NetResource.count
98
+ num_subscriptions = Subscription.count
99
+ post '/create', {:net_resource => {:url => n.url, :update_period => 20}, :subscription => s}, basic_auth_creds
100
+ follow_redirect!
101
+ end
102
+
103
+ should "redirect" do
104
+ assert_equal "http://example.org/", last_request.url
105
+ assert_equal num_resources, NetResource.count
106
+ assert_equal num_subscriptions + 1, Subscription.count
107
+ end
108
+ end
109
+ end
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
118
+
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
127
+
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
134
+ end
135
+
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
143
+ end
144
+
145
+ private
146
+
147
+ def clear_database
148
+ NetResource.all.each { |n| n.destroy }
149
+ Subscription.all.each { |s| s.destroy }
150
+ end
151
+
152
+ end
153
+
@@ -0,0 +1,45 @@
1
+ require File.dirname(__FILE__) + '/helper'
2
+
3
+ class SubscriptionTest < Test::Unit::TestCase
4
+
5
+ context "A Subscription instance" do
6
+
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")
10
+ @subscription = ::Subscription.new
11
+ end
12
+
13
+ should "validate the url" do
14
+ @subscription.net_resource = @resource
15
+ assert !@subscription.valid?
16
+ @subscription.url = "http://foo.com/notify"
17
+ @subscription.save!
18
+ assert @subscription.valid?
19
+ @subscription.url = "foo"
20
+ assert !@subscription.valid?
21
+ @subscription.url = "https://foo.bar.org"
22
+ assert @subscription.valid?
23
+ @subscription.url = "mailto:foo@bar.org"
24
+ assert !@subscription.valid?
25
+ end
26
+
27
+ should "have a working association with net resource" do
28
+ assert @subscription.respond_to?("net_resource")
29
+ assert_nothing_raised do
30
+ @subscription.net_resource = @resource
31
+ end
32
+ end
33
+
34
+ should "be invalid unless it belongs to a NetResource" do
35
+ @subscription.url = "http://example.org/foo"
36
+ assert !@subscription.valid?
37
+ @subscription.net_resource = @resource
38
+ @subscription.save!
39
+ assert @subscription.valid?
40
+ end
41
+
42
+ end
43
+
44
+ end
45
+
metadata ADDED
@@ -0,0 +1,231 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: octopus
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - dave@boomer
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-05-13 00:00:00 +01:00
18
+ default_executable: octopus
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: datamapper
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ - 10
30
+ - 1
31
+ version: 0.10.1
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: do_sqlite3
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 0
43
+ - 10
44
+ - 0
45
+ version: 0.10.0
46
+ type: :runtime
47
+ version_requirements: *id002
48
+ - !ruby/object:Gem::Dependency
49
+ name: sinatra
50
+ prerelease: false
51
+ requirement: &id003 !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ segments:
56
+ - 0
57
+ - 9
58
+ - 4
59
+ version: 0.9.4
60
+ type: :runtime
61
+ version_requirements: *id003
62
+ - !ruby/object:Gem::Dependency
63
+ name: thin
64
+ prerelease: false
65
+ requirement: &id004 !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ segments:
70
+ - 1
71
+ - 2
72
+ - 5
73
+ version: 1.2.5
74
+ type: :runtime
75
+ version_requirements: *id004
76
+ - !ruby/object:Gem::Dependency
77
+ name: rack-flash
78
+ prerelease: false
79
+ requirement: &id005 !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ segments:
84
+ - 0
85
+ - 1
86
+ - 1
87
+ version: 0.1.1
88
+ type: :runtime
89
+ version_requirements: *id005
90
+ - !ruby/object:Gem::Dependency
91
+ name: rack
92
+ prerelease: false
93
+ requirement: &id006 !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ segments:
98
+ - 1
99
+ - 0
100
+ - 1
101
+ version: 1.0.1
102
+ type: :runtime
103
+ version_requirements: *id006
104
+ - !ruby/object:Gem::Dependency
105
+ name: thoughtbot-shoulda
106
+ prerelease: false
107
+ requirement: &id007 !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ segments:
112
+ - 2
113
+ - 10
114
+ - 2
115
+ version: 2.10.2
116
+ type: :development
117
+ version_requirements: *id007
118
+ - !ruby/object:Gem::Dependency
119
+ name: rack-test
120
+ prerelease: false
121
+ requirement: &id008 !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ segments:
126
+ - 0
127
+ - 5
128
+ - 2
129
+ version: 0.5.2
130
+ type: :development
131
+ version_requirements: *id008
132
+ - !ruby/object:Gem::Dependency
133
+ name: notahat-machinist
134
+ prerelease: false
135
+ requirement: &id009 !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ segments:
140
+ - 1
141
+ - 0
142
+ - 3
143
+ version: 1.0.3
144
+ type: :development
145
+ version_requirements: *id009
146
+ description: Grabs stuff off the net and notifies interested subscribers.
147
+ email: dave.hrycyszyn@headlondon.com
148
+ executables:
149
+ - octopus
150
+ extensions: []
151
+
152
+ extra_rdoc_files:
153
+ - LICENSE
154
+ - README.rdoc
155
+ files:
156
+ - .document
157
+ - .gitignore
158
+ - LICENSE
159
+ - README.rdoc
160
+ - Rakefile
161
+ - VERSION
162
+ - bin/octopus
163
+ - doc/octopus.zargo
164
+ - lib/ext/array_ext.rb
165
+ - lib/ext/partials.rb
166
+ - lib/ext/reloader.rb
167
+ - lib/init.rb
168
+ - lib/octopus.rb
169
+ - lib/octopus/config.ru
170
+ - lib/octopus/grabbers/generic_http.rb
171
+ - lib/octopus/models/net_resource.rb
172
+ - lib/octopus/models/subscription.rb
173
+ - lib/octopus/public/default.css
174
+ - lib/octopus/public/images/bg01.jpg
175
+ - lib/octopus/public/images/bg02.jpg
176
+ - lib/octopus/public/images/bg03.jpg
177
+ - lib/octopus/public/images/bg04.jpg
178
+ - lib/octopus/public/images/img01.jpg
179
+ - lib/octopus/public/images/img02.gif
180
+ - lib/octopus/public/images/img03.gif
181
+ - lib/octopus/public/images/img04.gif
182
+ - lib/octopus/public/images/img05.gif
183
+ - lib/octopus/public/images/img06.jpg
184
+ - lib/octopus/public/images/spacer.gif
185
+ - lib/octopus/views/edit.erb
186
+ - lib/octopus/views/index.erb
187
+ - lib/octopus/views/layout.erb
188
+ - lib/octopus/views/new.erb
189
+ - lib/octopus/views/resource_list_item.erb
190
+ - octopus.gemspec
191
+ - test/helper.rb
192
+ - test/support/blueprints.rb
193
+ - test/test_net_resource.rb
194
+ - test/test_octopus.rb
195
+ - test/test_subscription.rb
196
+ has_rdoc: true
197
+ homepage: http://github.com/futurechimp/octopus
198
+ licenses: []
199
+
200
+ post_install_message:
201
+ rdoc_options:
202
+ - --charset=UTF-8
203
+ require_paths:
204
+ - lib
205
+ required_ruby_version: !ruby/object:Gem::Requirement
206
+ requirements:
207
+ - - ">="
208
+ - !ruby/object:Gem::Version
209
+ segments:
210
+ - 0
211
+ version: "0"
212
+ required_rubygems_version: !ruby/object:Gem::Requirement
213
+ requirements:
214
+ - - ">="
215
+ - !ruby/object:Gem::Version
216
+ segments:
217
+ - 0
218
+ version: "0"
219
+ requirements: []
220
+
221
+ rubyforge_project:
222
+ rubygems_version: 1.3.6
223
+ signing_key:
224
+ specification_version: 3
225
+ summary: An experimental octopus implementation.
226
+ test_files:
227
+ - test/support/blueprints.rb
228
+ - test/test_subscription.rb
229
+ - test/test_net_resource.rb
230
+ - test/test_octopus.rb
231
+ - test/helper.rb