simplepub 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/.travis.yml +3 -0
- data/CHANGELOG.md +49 -0
- data/Gemfile +4 -0
- data/LICENSE +20 -0
- data/LICENSE.txt +22 -0
- data/README.md +146 -0
- data/Rakefile +8 -0
- data/app/assets/javascripts/simplepub.js +97 -0
- data/bin/simplepub +5 -0
- data/lib/generators/simplepub/install_generator.rb +17 -0
- data/lib/simplepub/cli/app.rb +13 -0
- data/lib/simplepub/cli/config.rb +33 -0
- data/lib/simplepub/cli/server.rb +64 -0
- data/lib/simplepub/cli.rb +7 -0
- data/lib/simplepub/configuration.rb +48 -0
- data/lib/simplepub/engine.rb +16 -0
- data/lib/simplepub/error.rb +7 -0
- data/lib/simplepub/faye_extension.rb +43 -0
- data/lib/simplepub/interface_methods.rb +61 -0
- data/lib/simplepub/rack_config.ru +10 -0
- data/lib/simplepub/version.rb +3 -0
- data/lib/simplepub/view_helpers.rb +22 -0
- data/lib/simplepub.rb +24 -0
- data/lib/templates/simplepub.ru +10 -0
- data/lib/templates/simplepub.yml +10 -0
- data/simplepub.gemspec +29 -0
- data/spec/fixtures/simplepub.yml +8 -0
- data/spec/javascripts/helpers/SpecHelper.js +15 -0
- data/spec/javascripts/simplepub_spec.js +165 -0
- data/spec/javascripts/support/jasmine.yml +76 -0
- data/spec/javascripts/support/jasmine_config.rb +23 -0
- data/spec/javascripts/support/jasmine_helper.rb +11 -0
- data/spec/javascripts/support/jasmine_runner.rb +32 -0
- data/spec/simplepub/faye_extension_spec.rb +67 -0
- data/spec/simplepub_spec.rb +148 -0
- data/spec/spec_helper.rb +7 -0
- metadata +208 -0
@@ -0,0 +1,148 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Simplepub do
|
4
|
+
before(:each) do
|
5
|
+
Simplepub.reset_config
|
6
|
+
end
|
7
|
+
|
8
|
+
it "defaults server to nil" do
|
9
|
+
Simplepub.config[:server].should be_nil
|
10
|
+
end
|
11
|
+
|
12
|
+
it "defaults signature_expiration to nil" do
|
13
|
+
Simplepub.config[:signature_expiration].should be_nil
|
14
|
+
end
|
15
|
+
|
16
|
+
it "defaults subscription timestamp to current time in milliseconds" do
|
17
|
+
time = Time.now
|
18
|
+
Time.stub(:now).and_return(time)
|
19
|
+
Simplepub.subscription[:timestamp].should eq((time.to_f * 1000).round)
|
20
|
+
end
|
21
|
+
|
22
|
+
it "allows block configuration" do
|
23
|
+
Simplepub.configure do |config|
|
24
|
+
config.server = "http://example.com/faye"
|
25
|
+
end
|
26
|
+
Simplepub.config[:server].should eq("http://example.com/faye")
|
27
|
+
end
|
28
|
+
|
29
|
+
it "loads a simple configuration file via load_config" do
|
30
|
+
Simplepub.load_config("spec/fixtures/simplepub.yml", "production")
|
31
|
+
Simplepub.config[:server].should eq("http://example.com/faye")
|
32
|
+
Simplepub.config[:secret_token].should eq("PRODUCTION_SECRET_TOKEN")
|
33
|
+
Simplepub.config[:signature_expiration].should eq(600)
|
34
|
+
end
|
35
|
+
|
36
|
+
it "raises an exception if an invalid environment is passed to load_config" do
|
37
|
+
lambda {
|
38
|
+
Simplepub.load_config("spec/fixtures/simplepub.yml", :test)
|
39
|
+
}.should raise_error ArgumentError
|
40
|
+
end
|
41
|
+
|
42
|
+
it "includes channel, server, and custom time in subscription" do
|
43
|
+
Simplepub.config[:server] = "server"
|
44
|
+
subscription = Simplepub.subscription(:timestamp => 123, :channel => "hello")
|
45
|
+
subscription[:timestamp].should eq(123)
|
46
|
+
subscription[:channel].should eq("hello")
|
47
|
+
subscription[:server].should eq("server")
|
48
|
+
end
|
49
|
+
|
50
|
+
it "does a sha1 digest of channel, timestamp, and secret token" do
|
51
|
+
Simplepub.config[:secret_token] = "token"
|
52
|
+
subscription = Simplepub.subscription(:timestamp => 123, :channel => "channel")
|
53
|
+
subscription[:signature].should eq(Digest::SHA1.hexdigest("tokenchannel123"))
|
54
|
+
end
|
55
|
+
|
56
|
+
it "formats a message hash given a channel and a string for eval" do
|
57
|
+
Simplepub.config[:secret_token] = "token"
|
58
|
+
Simplepub.message("chan", "foo").should eq(
|
59
|
+
:ext => {:simplepub_token => "token"},
|
60
|
+
:channel => "chan",
|
61
|
+
:data => {
|
62
|
+
:channel => "chan",
|
63
|
+
:eval => "foo"
|
64
|
+
}
|
65
|
+
)
|
66
|
+
end
|
67
|
+
|
68
|
+
it "formats a message hash given a channel and a hash" do
|
69
|
+
Simplepub.config[:secret_token] = "token"
|
70
|
+
Simplepub.message("chan", :foo => "bar").should eq(
|
71
|
+
:ext => {:simplepub_token => "token"},
|
72
|
+
:channel => "chan",
|
73
|
+
:data => {
|
74
|
+
:channel => "chan",
|
75
|
+
:data => {:foo => "bar"}
|
76
|
+
}
|
77
|
+
)
|
78
|
+
end
|
79
|
+
|
80
|
+
it "publish message as json to server using Net::HTTP" do
|
81
|
+
Simplepub.config[:server] = "http://localhost"
|
82
|
+
message = 'foo'
|
83
|
+
form = double(:post).as_null_object
|
84
|
+
http = double(:http).as_null_object
|
85
|
+
|
86
|
+
Net::HTTP::Post.should_receive(:new).with('/').and_return(form)
|
87
|
+
form.should_receive(:set_form_data).with(message: 'foo'.to_json)
|
88
|
+
|
89
|
+
Net::HTTP.should_receive(:new).with('localhost', 80).and_return(http)
|
90
|
+
http.should_receive(:start).and_yield(http)
|
91
|
+
http.should_receive(:request).with(form).and_return(:result)
|
92
|
+
|
93
|
+
Simplepub.publish_message(message).should eq(:result)
|
94
|
+
end
|
95
|
+
|
96
|
+
it "it should use HTTPS if the server URL says so" do
|
97
|
+
Simplepub.config[:server] = "https://localhost"
|
98
|
+
http = double(:http).as_null_object
|
99
|
+
|
100
|
+
Net::HTTP.should_receive(:new).and_return(http)
|
101
|
+
http.should_receive(:use_ssl=).with(true)
|
102
|
+
|
103
|
+
Simplepub.publish_message('foo')
|
104
|
+
end
|
105
|
+
|
106
|
+
it "it should not use HTTPS if the server URL says not to" do
|
107
|
+
Simplepub.config[:server] = "http://localhost"
|
108
|
+
http = double(:http).as_null_object
|
109
|
+
|
110
|
+
Net::HTTP.should_receive(:new).and_return(http)
|
111
|
+
http.should_receive(:use_ssl=).with(false)
|
112
|
+
|
113
|
+
Simplepub.publish_message('foo')
|
114
|
+
end
|
115
|
+
|
116
|
+
it "raises an exception if no server is specified when calling publish_message" do
|
117
|
+
lambda {
|
118
|
+
Simplepub.publish_message("foo")
|
119
|
+
}.should raise_error(Simplepub::Error)
|
120
|
+
end
|
121
|
+
|
122
|
+
it "publish_to passes message to publish_message call" do
|
123
|
+
Simplepub.should_receive(:message).with("chan", "foo").and_return("message")
|
124
|
+
Simplepub.should_receive(:publish_message).with("message").and_return(:result)
|
125
|
+
Simplepub.publish_to("chan", "foo").should eq(:result)
|
126
|
+
end
|
127
|
+
|
128
|
+
it "has a Faye rack app instance" do
|
129
|
+
Simplepub.faye_app.should be_kind_of(Faye::RackAdapter)
|
130
|
+
end
|
131
|
+
|
132
|
+
it "says signature has expired when time passed in is greater than expiration" do
|
133
|
+
Simplepub.config[:signature_expiration] = 30*60
|
134
|
+
time = Simplepub.subscription[:timestamp] - 31*60*1000
|
135
|
+
Simplepub.signature_expired?(time).should be_true
|
136
|
+
end
|
137
|
+
|
138
|
+
it "says signature has not expired when time passed in is less than expiration" do
|
139
|
+
Simplepub.config[:signature_expiration] = 30*60
|
140
|
+
time = Simplepub.subscription[:timestamp] - 29*60*1000
|
141
|
+
Simplepub.signature_expired?(time).should be_false
|
142
|
+
end
|
143
|
+
|
144
|
+
it "says signature has not expired when expiration is nil" do
|
145
|
+
Simplepub.config[:signature_expiration] = nil
|
146
|
+
Simplepub.signature_expired?(0).should be_false
|
147
|
+
end
|
148
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,208 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: simplepub
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.4
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jorge Calás Lozano
|
8
|
+
- Ryan Bates
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-11-06 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: faye
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - '>='
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '0'
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - '>='
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '0'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: thor
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - '>='
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - '>='
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: hashie
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - '>='
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
type: :runtime
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - '>='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: thin
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
type: :runtime
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: bundler
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ~>
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '1.3'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ~>
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '1.3'
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: rake
|
86
|
+
requirement: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - '>='
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
type: :development
|
92
|
+
prerelease: false
|
93
|
+
version_requirements: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - '>='
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
- !ruby/object:Gem::Dependency
|
99
|
+
name: rspec
|
100
|
+
requirement: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - '>='
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
type: :development
|
106
|
+
prerelease: false
|
107
|
+
version_requirements: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - '>='
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0'
|
112
|
+
- !ruby/object:Gem::Dependency
|
113
|
+
name: jasmine
|
114
|
+
requirement: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - '>='
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
type: :development
|
120
|
+
prerelease: false
|
121
|
+
version_requirements: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - '>='
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
description: Simple private pub/sub messaging for Ruby using Faye.
|
127
|
+
email:
|
128
|
+
- calas@qvitta.net
|
129
|
+
- ryan@railscasts.com
|
130
|
+
executables:
|
131
|
+
- simplepub
|
132
|
+
extensions: []
|
133
|
+
extra_rdoc_files: []
|
134
|
+
files:
|
135
|
+
- .gitignore
|
136
|
+
- .rspec
|
137
|
+
- .travis.yml
|
138
|
+
- CHANGELOG.md
|
139
|
+
- Gemfile
|
140
|
+
- LICENSE
|
141
|
+
- LICENSE.txt
|
142
|
+
- README.md
|
143
|
+
- Rakefile
|
144
|
+
- app/assets/javascripts/simplepub.js
|
145
|
+
- bin/simplepub
|
146
|
+
- lib/generators/simplepub/install_generator.rb
|
147
|
+
- lib/simplepub.rb
|
148
|
+
- lib/simplepub/cli.rb
|
149
|
+
- lib/simplepub/cli/app.rb
|
150
|
+
- lib/simplepub/cli/config.rb
|
151
|
+
- lib/simplepub/cli/server.rb
|
152
|
+
- lib/simplepub/configuration.rb
|
153
|
+
- lib/simplepub/engine.rb
|
154
|
+
- lib/simplepub/error.rb
|
155
|
+
- lib/simplepub/faye_extension.rb
|
156
|
+
- lib/simplepub/interface_methods.rb
|
157
|
+
- lib/simplepub/rack_config.ru
|
158
|
+
- lib/simplepub/version.rb
|
159
|
+
- lib/simplepub/view_helpers.rb
|
160
|
+
- lib/templates/simplepub.ru
|
161
|
+
- lib/templates/simplepub.yml
|
162
|
+
- simplepub.gemspec
|
163
|
+
- spec/fixtures/simplepub.yml
|
164
|
+
- spec/javascripts/helpers/SpecHelper.js
|
165
|
+
- spec/javascripts/simplepub_spec.js
|
166
|
+
- spec/javascripts/support/jasmine.yml
|
167
|
+
- spec/javascripts/support/jasmine_config.rb
|
168
|
+
- spec/javascripts/support/jasmine_helper.rb
|
169
|
+
- spec/javascripts/support/jasmine_runner.rb
|
170
|
+
- spec/simplepub/faye_extension_spec.rb
|
171
|
+
- spec/simplepub_spec.rb
|
172
|
+
- spec/spec_helper.rb
|
173
|
+
homepage: https://speedyrails.com
|
174
|
+
licenses:
|
175
|
+
- MIT
|
176
|
+
metadata: {}
|
177
|
+
post_install_message:
|
178
|
+
rdoc_options: []
|
179
|
+
require_paths:
|
180
|
+
- lib
|
181
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
182
|
+
requirements:
|
183
|
+
- - '>='
|
184
|
+
- !ruby/object:Gem::Version
|
185
|
+
version: '0'
|
186
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
187
|
+
requirements:
|
188
|
+
- - '>='
|
189
|
+
- !ruby/object:Gem::Version
|
190
|
+
version: '0'
|
191
|
+
requirements: []
|
192
|
+
rubyforge_project:
|
193
|
+
rubygems_version: 2.0.3
|
194
|
+
signing_key:
|
195
|
+
specification_version: 4
|
196
|
+
summary: Simple private pub/sub messaging for Ruby.
|
197
|
+
test_files:
|
198
|
+
- spec/fixtures/simplepub.yml
|
199
|
+
- spec/javascripts/helpers/SpecHelper.js
|
200
|
+
- spec/javascripts/simplepub_spec.js
|
201
|
+
- spec/javascripts/support/jasmine.yml
|
202
|
+
- spec/javascripts/support/jasmine_config.rb
|
203
|
+
- spec/javascripts/support/jasmine_helper.rb
|
204
|
+
- spec/javascripts/support/jasmine_runner.rb
|
205
|
+
- spec/simplepub/faye_extension_spec.rb
|
206
|
+
- spec/simplepub_spec.rb
|
207
|
+
- spec/spec_helper.rb
|
208
|
+
has_rdoc:
|