octopus 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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,233 @@
1
+ /*
2
+ Design by Free CSS Templates
3
+ http://www.freecsstemplates.org
4
+ Released for free under a Creative Commons Attribution 2.5 License
5
+ */
6
+
7
+ body {
8
+ margin: 0;
9
+ padding: 0;
10
+ background: #FFFFFF url(images/bg01.jpg) repeat-x top left;
11
+ font-size: 13px;
12
+ color: #7F7F7F;
13
+ }
14
+
15
+ body, th, td, input, textarea, select, option {
16
+ font-weight: normal;
17
+ font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
18
+ }
19
+
20
+ h1, h2, h3 {
21
+ font-weight: normal;
22
+ color: #484848;
23
+ }
24
+
25
+ h1 {
26
+ text-transform: lowercase;
27
+ letter-spacing: -1px;
28
+ font-size: 24px;
29
+ }
30
+
31
+ h2 {
32
+ text-transform: lowercase;
33
+ letter-spacing: -1px;
34
+ font-size: 24px;
35
+ }
36
+
37
+ h3 {
38
+ font-size: 1em;
39
+ }
40
+
41
+ p, ul, ol {
42
+ line-height: 200%;
43
+ }
44
+
45
+ blockquote {
46
+ padding-left: 1em;
47
+ }
48
+
49
+ blockquote p, blockquote ul, blockquote ol {
50
+ line-height: normal;
51
+ font-style: italic;
52
+ }
53
+
54
+ a {
55
+ color: #7ACE11;
56
+ }
57
+
58
+ a:hover {
59
+ text-decoration: none;
60
+ color: #7ACE11;
61
+ }
62
+
63
+ /* Header */
64
+
65
+ #header {
66
+ width: 890px;
67
+ height: 190px;
68
+ margin: 0px auto;
69
+ }
70
+
71
+ /* Logo */
72
+
73
+ #logo {
74
+ float: left;
75
+ padding: 40px 0 0 0;
76
+ }
77
+
78
+ #logo h1 {
79
+ margin: 0;
80
+ text-transform: lowercase;
81
+ letter-spacing: -2px;
82
+ font-size: 3.6em;
83
+ font-weight: normal;
84
+ color: #FFFFFF;
85
+ }
86
+
87
+ #logo h1 a {
88
+ padding-right: 20px;
89
+ text-decoration: none;
90
+ color: #FFFFFF;
91
+ }
92
+
93
+ #logo p {
94
+ margin: -5px 0 0 0;
95
+ text-transform: uppercase;
96
+ font-size: 1.22em;
97
+ letter-spacing: -1px;
98
+ }
99
+
100
+ #logo a {
101
+ text-decoration: none;
102
+ color: #FFFFFF;
103
+ }
104
+
105
+ /* Menu */
106
+
107
+ #menu {
108
+ float: right;
109
+ }
110
+
111
+ #menu ul {
112
+ margin: 0px;
113
+ padding: 93px 0px 0px 0px;
114
+ list-style: none;
115
+ }
116
+
117
+ #menu li {
118
+ display: inline;
119
+ }
120
+
121
+ #menu a {
122
+ display: block;
123
+ float: left;
124
+ margin-left: 20px;
125
+ text-decoration: none;
126
+ text-transform: lowercase;
127
+ font-size: 1.36em;
128
+ color: #FFFFFF;
129
+ }
130
+
131
+ #menu a:hover, .active a {
132
+ border-bottom: 3px solid #FFFFFF;
133
+ }
134
+
135
+
136
+ /* Page */
137
+
138
+ #page {
139
+ width: 890px;
140
+ margin: 0 auto;
141
+ }
142
+
143
+ /* Content */
144
+
145
+ #content {
146
+ float: left;
147
+ width: 590px;
148
+ }
149
+
150
+ .post {
151
+ padding: 20px 20px;
152
+ background: url(images/bg04.jpg) no-repeat top left;
153
+ }
154
+
155
+ .title {
156
+ margin: 0;
157
+ border-bottom: 2px solid #484848;
158
+ color: #484848;
159
+ }
160
+
161
+ .byline {
162
+ margin: 0;
163
+ color: #D79B00;
164
+ }
165
+
166
+ .meta {
167
+ text-align: left;
168
+ color: #646464;
169
+ }
170
+
171
+ .meta .more {
172
+ padding-left: 20px;
173
+ background: url(images/img03.gif) no-repeat left center;
174
+ }
175
+
176
+ .meta .comments {
177
+ padding-left: 20px;
178
+ background: url(images/img04.gif) no-repeat left center;
179
+ }
180
+
181
+ /* Sidebar */
182
+
183
+ #sidebar {
184
+ float: right;
185
+ width: 240px;
186
+ }
187
+
188
+ #sidebar ul {
189
+ margin: 0;
190
+ padding: 0;
191
+ list-style: none;
192
+ }
193
+
194
+ #sidebar li {
195
+ }
196
+
197
+ #sidebar li ul {
198
+ padding: 15px 0;
199
+ }
200
+
201
+ #sidebar li li {
202
+ padding-left: 20px;
203
+ border-bottom: 1px dotted #7B9418;
204
+ }
205
+
206
+ #sidebar h2 {
207
+ margin: 0;
208
+ padding: 5px 0 0 20px;
209
+ background: url(images/img06.jpg) no-repeat left 80%;
210
+ }
211
+
212
+ #sidebar a {
213
+ text-decoration: none;
214
+ }
215
+
216
+ #sidebar a:hover {
217
+ }
218
+
219
+ /* Footer */
220
+
221
+ #footer {
222
+ clear: both;
223
+ margin: 0px;
224
+ height: 80px;
225
+ background: #F2F2F2 url(images/bg02.jpg) repeat-x left top;
226
+ }
227
+
228
+ #footer p {
229
+ padding: 20px 0;
230
+ text-align: center;
231
+ font-size: smaller;
232
+ color: #717171;
233
+ }
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -0,0 +1,29 @@
1
+ <div class="post">
2
+ <h1 class="title">Edit resource</h1>
3
+ <div class="entry">
4
+ <% unless @resource.errors.empty? %>
5
+ <div class="errors">
6
+ <h2>Errors on NetResource</h2>
7
+ <ul>
8
+ <% @resource.errors.each do |error| %>
9
+ <li><%= error %></li>
10
+ <% end %>
11
+ </ul>
12
+ </div>
13
+ <% end %>
14
+
15
+ <form action="/update/<%= @resource.id %>" method="POST">
16
+ <input name="_method" value="PUT" type="hidden"/>
17
+
18
+ <p><strong>Resource url:</strong>
19
+ The url of the internet resource you want to watch for changes.
20
+ <input name="net_resource[url]" value="<%= @resource.url %>" id="net_resource_url" size="70"></input></p>
21
+
22
+ <p><strong>Update period:</strong>
23
+ The number of seconds between updates, defaults to 1200 seconds (20 minutes) if left blank.
24
+ <input name="net_resource[update_period]" value="<%= @resource.update_period %>"id="net_resource_update_period" size="4"></input></p>
25
+
26
+ <input type="submit" value="Save"/>
27
+ </form>
28
+ </div>
29
+
@@ -0,0 +1,21 @@
1
+ <div class="post">
2
+ <h1 class="title">Welcome to your octopus</h1>
3
+ <div class="entry">
4
+ <p>It is watching <strong><%= @resource_count %> resources</strong> on the net,
5
+ and has a total of <strong><%= @subscription_count %> subscriptions</strong>.</p>
6
+ <form action="/new_or_edit" method="POST">
7
+ <p>Add, edit, or delete a resource by pasting its URL in here:<br/>
8
+ <input name="net_resource[url]" id="net_resource_url" size="70"/>
9
+ </p>
10
+ <input type="submit" value="Go!"/>
11
+ </form>
12
+
13
+ <% unless @resources.empty? %>
14
+ <p>Here are the next resources which will be checked for changes:</p>
15
+ <ul>
16
+ <%= partial :resource_list_item, :collection => @resources %>
17
+ </ul>
18
+ <% end %>
19
+ </div>
20
+ </div>
21
+
@@ -0,0 +1,65 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2
+ <!--
3
+ Design by Free CSS Templates
4
+ http://www.freecsstemplates.org
5
+ Released for free under a Creative Commons Attribution 2.5 License
6
+
7
+ Name : Unqualified
8
+ Description: A two-column, fixed-width design.
9
+ Version : 1.0
10
+ Released : 20071220
11
+
12
+ -->
13
+ <html xmlns="http://www.w3.org/1999/xhtml">
14
+ <head>
15
+ <meta http-equiv="content-type" content="text/html; charset=utf-8" />
16
+ <title>Octopus Admin</title>
17
+ <meta name="keywords" content="" />
18
+ <meta name="description" content="" />
19
+ <link href="/default.css" rel="stylesheet" type="text/css" media="screen" />
20
+ </head>
21
+ <body>
22
+ <!-- start header -->
23
+ <div id="header">
24
+ <div id="logo">
25
+ <h1><a href="/">Octopus</a></h1>
26
+ <p>Admin</p>
27
+ </div>
28
+ <div id="menu">
29
+ <ul>
30
+ <li <%= 'class="active"' if request.path_info == "/" %>><a href="/">Home</a></li>
31
+ <li <%= 'class="active"' if request.path_info == "/new" %>><a href="/new">New</a></li>
32
+ </ul>
33
+ </div>
34
+ </div>
35
+ <!-- end header -->
36
+ <!-- start page -->
37
+ <div id="page">
38
+ <!-- start content -->
39
+ <div id="content">
40
+
41
+ <%= yield %>
42
+
43
+ </div>
44
+ <!-- end content -->
45
+ <!-- start sidebar -->
46
+ <div id="sidebar">
47
+ <ul>
48
+ <li>
49
+ <h2>More about octopi</h2>
50
+ <ul>
51
+ <li><a href="http://octopile.net">Octopile</a></li>
52
+ </ul>
53
+ </li>
54
+ </div>
55
+ <!-- end sidebar -->
56
+ </div>
57
+ <!-- end page -->
58
+
59
+
60
+ <div id="footer">
61
+ <p>Design by <a href="http://www.freecsstemplates.org/">Free CSS Templates</a> &nbsp;&bull;&nbsp; Icons by <a href="http://www.famfamfam.com/">FAMFAMFAM</a>.</p>
62
+ </div>
63
+ </body>
64
+ </html>
65
+
@@ -0,0 +1,42 @@
1
+ <div class="post">
2
+ <h1 class="title">Create a new resource</h1>
3
+ <div class="entry">
4
+ <% unless @resource.errors.empty? %>
5
+ <div class="errors">
6
+ <h2>Errors on NetResource</h2>
7
+ <ul>
8
+ <% @resource.errors.each do |error| %>
9
+ <li><%= error %></li>
10
+ <% end %>
11
+ </ul>
12
+ </div>
13
+ <% end %>
14
+
15
+ <% unless @subscription.errors.empty? %>
16
+ <div class="errors">
17
+ <h2>Errors on Subscription</h2>
18
+ <ul>
19
+ <% @subscription.errors.each do |error| %>
20
+ <li><%= error %></li>
21
+ <% end %>
22
+ </ul>
23
+ </div>
24
+ <% end %>
25
+
26
+ <form action="/create" method="POST">
27
+ <p><strong>Resource url:</strong>
28
+ The url of the internet resource you want to watch for changes.
29
+ <input name="net_resource[url]" id="net_resource_url" size="70"></input></p>
30
+
31
+ <p><strong>Update period:</strong>
32
+ The number of seconds between updates, defaults to 1200 seconds (20 minutes) if left blank.
33
+ <input name="net_resource[update_period]" id="net_resource_update_period" size="4"></input></p>
34
+
35
+ <h2 class="title">The Subscription</h2>
36
+ <p><strong>Notification url:</strong>
37
+ The url that should be hit when the resource changes.
38
+ <input name="subscription[url]" id="subscription_url" size="70"></input></p>
39
+ <input type="submit" value="Save"/>
40
+ </form>
41
+ </div>
42
+
@@ -0,0 +1,9 @@
1
+ <li>
2
+ <%=h resource_list_item.url %><br/>
3
+ <%= resource_list_item.subscriptions.count %> subscriptions<br/>
4
+ Last updated at <%=h resource_list_item.last_updated.strftime("%m/%d/%Y at %H:%M:%S") unless resource_list_item.last_updated.nil? %><br/>
5
+ Last checked at <%=h resource_list_item.updated_at.strftime("%m/%d/%Y at %H:%M:%S") %><br/>
6
+ Next check will be at <%=h resource_list_item.next_update.strftime("%m/%d/%Y at %H:%M:%S") %><br/>
7
+ Checked every <%= h resource_list_item.update_period %> seconds.
8
+ </li>
9
+
data/lib/octopus.rb ADDED
@@ -0,0 +1,81 @@
1
+ require File.dirname(__FILE__) + '/init'
2
+
3
+ # Shows an octopus status page.
4
+ #
5
+ get '/' do
6
+ @resources = NetResource.all(:limit => 50, :order => [:next_update.asc])
7
+ @resource_count = NetResource.count
8
+ @subscription_count = Subscription.count
9
+ erb :index
10
+ end
11
+
12
+ # Displays a form to create a new resource.
13
+ #
14
+ get '/new' do
15
+ @resource = NetResource.new
16
+ @subscription = Subscription.new
17
+ erb :new
18
+ end
19
+
20
+
21
+ # Displays an edit page for a resource.
22
+ #
23
+ get '/edit/:id' do
24
+ @resource = NetResource.get(params[:id])
25
+ erb :edit
26
+ end
27
+
28
+
29
+ # Creates a resource with an associated subscription. If the resource already
30
+ # exists, the subscription will be appended to it instead of creating a new one.
31
+ #
32
+ post '/create' do
33
+ @resource = NetResource.first(:url => params[:net_resource][:url])
34
+ @resource = NetResource.new(params[:net_resource]) if @resource.nil?
35
+ @subscription = Subscription.new(params[:subscription])
36
+ @resource.subscriptions << @subscription
37
+ if @resource.save
38
+ flash[:notice] = "Net resource created."
39
+ redirect '/'
40
+ else
41
+ erb :new
42
+ end
43
+ end
44
+
45
+
46
+ # Updates a resource.
47
+ #
48
+ put '/update/:id' do
49
+ @resource = NetResource.get(params[:id])
50
+ if @resource.update(params[:net_resource])
51
+ flash[:notice] = "Net resource updated."
52
+ redirect '/'
53
+ else
54
+ erb :edit
55
+ end
56
+ end
57
+
58
+
59
+ # Figures out whether it's getting a new resource to watch or is editing
60
+ # an existing resource and redirects the user appropriately.
61
+ #
62
+ post '/new_or_edit' do
63
+ resource = NetResource.first(:url => params[:net_resource][:url])
64
+ if resource.nil?
65
+ redirect '/new'
66
+ else
67
+ redirect "/edit/#{resource.id}"
68
+ end
69
+ end
70
+
71
+
72
+ # Starts the octopus grabbing thread. The thread will be reabsorbed into the
73
+ # main Sinatra/thin thread once the periodic timer is added.
74
+ #
75
+ Thread.new do
76
+ until EM.reactor_running?
77
+ sleep 1
78
+ end
79
+ Grabbers::GenericHttp.new
80
+ end
81
+
data/octopus.gemspec ADDED
@@ -0,0 +1,113 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{octopus}
8
+ s.version = "0.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["dave@boomer"]
12
+ s.date = %q{2010-05-13}
13
+ s.default_executable = %q{octopus}
14
+ s.description = %q{Grabs stuff off the net and notifies interested subscribers.}
15
+ s.email = %q{dave.hrycyszyn@headlondon.com}
16
+ s.executables = ["octopus"]
17
+ s.extra_rdoc_files = [
18
+ "LICENSE",
19
+ "README.rdoc"
20
+ ]
21
+ s.files = [
22
+ ".document",
23
+ ".gitignore",
24
+ "LICENSE",
25
+ "README.rdoc",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "bin/octopus",
29
+ "doc/octopus.zargo",
30
+ "lib/ext/array_ext.rb",
31
+ "lib/ext/partials.rb",
32
+ "lib/ext/reloader.rb",
33
+ "lib/init.rb",
34
+ "lib/octopus.rb",
35
+ "lib/octopus/config.ru",
36
+ "lib/octopus/grabbers/generic_http.rb",
37
+ "lib/octopus/models/net_resource.rb",
38
+ "lib/octopus/models/subscription.rb",
39
+ "lib/octopus/public/default.css",
40
+ "lib/octopus/public/images/bg01.jpg",
41
+ "lib/octopus/public/images/bg02.jpg",
42
+ "lib/octopus/public/images/bg03.jpg",
43
+ "lib/octopus/public/images/bg04.jpg",
44
+ "lib/octopus/public/images/img01.jpg",
45
+ "lib/octopus/public/images/img02.gif",
46
+ "lib/octopus/public/images/img03.gif",
47
+ "lib/octopus/public/images/img04.gif",
48
+ "lib/octopus/public/images/img05.gif",
49
+ "lib/octopus/public/images/img06.jpg",
50
+ "lib/octopus/public/images/spacer.gif",
51
+ "lib/octopus/views/edit.erb",
52
+ "lib/octopus/views/index.erb",
53
+ "lib/octopus/views/layout.erb",
54
+ "lib/octopus/views/new.erb",
55
+ "lib/octopus/views/resource_list_item.erb",
56
+ "octopus.gemspec",
57
+ "test/helper.rb",
58
+ "test/support/blueprints.rb",
59
+ "test/test_net_resource.rb",
60
+ "test/test_octopus.rb",
61
+ "test/test_subscription.rb"
62
+ ]
63
+ s.homepage = %q{http://github.com/futurechimp/octopus}
64
+ s.rdoc_options = ["--charset=UTF-8"]
65
+ s.require_paths = ["lib"]
66
+ s.rubygems_version = %q{1.3.6}
67
+ s.summary = %q{An experimental octopus implementation.}
68
+ s.test_files = [
69
+ "test/support/blueprints.rb",
70
+ "test/test_subscription.rb",
71
+ "test/test_net_resource.rb",
72
+ "test/test_octopus.rb",
73
+ "test/helper.rb"
74
+ ]
75
+
76
+ if s.respond_to? :specification_version then
77
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
78
+ s.specification_version = 3
79
+
80
+ 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"])
84
+ s.add_runtime_dependency(%q<thin>, [">= 1.2.5"])
85
+ s.add_runtime_dependency(%q<rack-flash>, [">= 0.1.1"])
86
+ s.add_runtime_dependency(%q<rack>, [">= 1.0.1"])
87
+ s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 2.10.2"])
88
+ s.add_development_dependency(%q<rack-test>, [">= 0.5.2"])
89
+ s.add_development_dependency(%q<notahat-machinist>, [">= 1.0.3"])
90
+ 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"])
94
+ s.add_dependency(%q<thin>, [">= 1.2.5"])
95
+ s.add_dependency(%q<rack-flash>, [">= 0.1.1"])
96
+ s.add_dependency(%q<rack>, [">= 1.0.1"])
97
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 2.10.2"])
98
+ s.add_dependency(%q<rack-test>, [">= 0.5.2"])
99
+ s.add_dependency(%q<notahat-machinist>, [">= 1.0.3"])
100
+ end
101
+ 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"])
105
+ s.add_dependency(%q<thin>, [">= 1.2.5"])
106
+ s.add_dependency(%q<rack-flash>, [">= 0.1.1"])
107
+ s.add_dependency(%q<rack>, [">= 1.0.1"])
108
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 2.10.2"])
109
+ s.add_dependency(%q<rack-test>, [">= 0.5.2"])
110
+ s.add_dependency(%q<notahat-machinist>, [">= 1.0.3"])
111
+ end
112
+ end
113
+
data/test/helper.rb ADDED
@@ -0,0 +1,50 @@
1
+ require 'rubygems'
2
+ require 'sinatra'
3
+ require 'rack/test'
4
+ require 'base64'
5
+ require 'machinist/data_mapper'
6
+ require 'faker'
7
+ require 'sham'
8
+ set :environment, :test
9
+ set :run, false
10
+ set :raise_errors, true
11
+ set :logging, false
12
+ require File.dirname(__FILE__) + '/../lib/init'
13
+ require File.dirname(__FILE__) + '/../lib/octopus'
14
+ require File.dirname(__FILE__) + '/support/blueprints'
15
+
16
+
17
+ module TestHelper
18
+
19
+ def app
20
+ # change to your app class if using the 'classy' style
21
+ Sinatra::Application.new
22
+ end
23
+
24
+ def body
25
+ last_response.body
26
+ end
27
+
28
+ def status
29
+ last_response.status
30
+ end
31
+
32
+ include Rack::Test::Methods
33
+
34
+ end
35
+
36
+
37
+ require 'test/unit'
38
+ require 'shoulda'
39
+
40
+
41
+ Test::Unit::TestCase.send(:include, TestHelper)
42
+
43
+ def basic_auth_creds(username = 'admin', password = 'admin')
44
+ {'HTTP_AUTHORIZATION'=> encode_credentials(username, password)}
45
+ end
46
+
47
+ def encode_credentials(username, password)
48
+ "Basic " + Base64.encode64("#{username}:#{password}")
49
+ end
50
+
@@ -0,0 +1,20 @@
1
+ Sham.url { "http://" + Faker::Internet.domain_name }
2
+ Sham.last_modified_hash {"foo#{rand(100000).to_s}".hash}
3
+ Sham.body { Faker::Lorem.sentence }
4
+
5
+ NetResource.blueprint do
6
+ url
7
+ last_modified_hash
8
+ update_period { 30 }
9
+ next_update { DateTime.now + 30 }
10
+ body
11
+ created_at DateTime.now
12
+ updated_at DateTime.now
13
+ end
14
+
15
+ Subscription.blueprint do
16
+ url
17
+ created_at DateTime.now
18
+ updated_at DateTime.now
19
+ end
20
+