pousse 0.0.4 → 0.0.5

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.
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 1.9.3-p374
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - "1.9.3-p374"
4
+ script: bundle exec rspec spec
data/Gemfile CHANGED
@@ -10,5 +10,6 @@ end
10
10
 
11
11
  group :test do
12
12
  gem 'rspec'
13
+ gem 'coveralls', require: false
13
14
  gem 'therubyracer', require: 'v8'
14
15
  end
data/README.md CHANGED
@@ -1,6 +1,13 @@
1
1
  # Pousse
2
2
 
3
- TODO: Write a gem description
3
+ [![Pousse](http://doc.agorize.com/pousse/poussette.png)](http://github.com/Studyka/pousse)
4
+
5
+
6
+ [![Build Status](https://travis-ci.org/Studyka/pousse.png?branch=master)](https://travis-ci.org/Studyka/pousse)
7
+ [![Dependency Status](https://gemnasium.com/Studyka/pousse.png)](https://gemnasium.com/Studyka/pousse)
8
+ [![Code Climate](https://codeclimate.com/github/Studyka/pousse.png)](https://codeclimate.com/github/Studyka/pousse)
9
+
10
+ Pousse enables you to add realtime to any rails application by sending javascript to users or group of users.
4
11
 
5
12
  ## Installation
6
13
 
@@ -16,25 +23,60 @@ Or install it yourself as:
16
23
 
17
24
  $ gem install pousse
18
25
 
26
+ ### Install your Poussette node server on heroku:
27
+
28
+ ```
29
+ git clone git@github.com:Studyka/poussette.git
30
+ cd poussette
31
+ heroku create <your-app>
32
+ heroku config:set POUSSE_SECRET=yoursecret # Used as encryption key
33
+ heroku addons:add redistogo
34
+ git push heroku master
35
+ heroku config | grep REDISTOGO_URL # This url is needed in the pousse initializer below
36
+ ```
37
+
19
38
  ## Usage
20
39
 
40
+
21
41
  Create an initializer config/initializer/pousse.rb
22
42
 
43
+ Set an envirnoment variable `REDISTOGO_URL` corresponding to the url previously greped
44
+
45
+ ### If you are using Heroku with RedisToGo:
46
+ ```
47
+ Pousse::configure do |config|
48
+ config.server = ENV['POUSSETTE_SERVER'] # Warning: You must specify the port in development mode (eg: http://mypousssette.herokuapp.com:80)
49
+ config.secret = ENV['POUSSE_SECRET']
50
+ if ENV['REDISTOGO_URL'].present?
51
+ uri = URI.parse(ENV['REDISTOGO_URL'])
52
+ config.redis = { host: uri.host, port: uri.port, password: uri.password }
53
+ end
54
+ end
55
+ ```
56
+ ### else (without Heroku):
23
57
  ```
24
58
  Pousse::configure do |config|
59
+ config.server = ''
60
+ config.secret = ''
61
+ config.redis = {
62
+ host: '',
63
+ port: '',
64
+ password: ''
65
+ }
25
66
  end
26
67
  ```
27
68
 
28
- Add this line to your layout :
69
+ Add this line to your layout:
29
70
 
30
71
  ```
31
- <script><%= Pousse::js([:everybody], [server], [secret]) %></script>
72
+ # Everybody is your channel
73
+ <%= javascript_tag Pousse::js([:everybody]) %>
32
74
  ```
33
75
 
34
76
 
35
- Create a new mailer in app/mailer/pousse.rb
77
+ Create a new mailer in `app/mailer/pousse_mailer.rb`
36
78
  ```
37
- class AlertMailer < Pousse::Mailer
79
+ class PousseMailer < Pousse::Mailer
38
80
  def send_alert
39
81
  mail(
40
82
  to: 'everybody',
@@ -44,14 +86,14 @@ class AlertMailer < Pousse::Mailer
44
86
  end
45
87
  ```
46
88
 
47
- ### Your node server on heroku :
89
+ ## Testing:
48
90
 
91
+ Add the following line in your `config/environments/test.rb`:
49
92
  ```
50
- git clone ...
51
- heroku ...
93
+ Pousse::Mailer.delivery_method = :test
52
94
  ```
53
95
 
54
- ### TODO :
96
+ ## TODO:
55
97
 
56
98
  - Should add some logging when redis is not available.
57
99
  - Should add some spec for the configuration.
data/lib/pousse/mailer.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  module Pousse
2
2
  class Mailer < ActionMailer::Base
3
- default delivery_method: Pousse::RedisDelivery
3
+ self.delivery_method = Pousse::RedisDelivery
4
+ default from: 'pousse@pousse.pousse'
4
5
  end
5
6
  end
@@ -7,6 +7,7 @@ module Pousse
7
7
  end
8
8
 
9
9
  def deliver!(mail)
10
+ redis = nil
10
11
  begin
11
12
  redis = Redis.new @redis_config
12
13
  mail.to.each do |to|
@@ -15,6 +16,8 @@ module Pousse
15
16
  rescue Exception => e
16
17
  #TODO: Use a real logguer ??
17
18
  puts "NOTIFICATION NOT DELIVERED: #{e.message}"
19
+ ensure
20
+ redis.quit unless redis.nil?
18
21
  end
19
22
  end
20
23
  end
@@ -1,3 +1,3 @@
1
1
  module Pousse
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -14,15 +14,29 @@ describe Pousse do
14
14
  body: 'alert("Générale !");'
15
15
  )
16
16
  end
17
- end
17
+ end
18
18
  end
19
19
 
20
20
  let :redis_instance do
21
- redis_instance = stub()
21
+ redis_instance = stub(quit: true)
22
22
  Redis.stub(new: redis_instance)
23
23
  redis_instance
24
24
  end
25
25
 
26
+
27
+ it 'uses default from' do
28
+ mailer.send_alert.from.should == ['pousse@pousse.pousse']
29
+ end
30
+
31
+ it 'uses delivery method' do
32
+ mailer.send_alert.delivery_method.should be_an_instance_of Pousse::RedisDelivery
33
+ end
34
+
35
+ it 'delivery method can be overwritten' do
36
+ mailer.delivery_method = :test
37
+ mailer.send_alert.delivery_method.should be_an_instance_of Mail::TestMailer
38
+ end
39
+
26
40
  it 'provide Pousse::Mailer' do
27
41
  expect{
28
42
  Class.new Pousse::Mailer
@@ -3,14 +3,14 @@ require 'spec_helper'
3
3
 
4
4
  describe Pousse::RedisDelivery do
5
5
 
6
- let :redis do
7
- Pousse::RedisDelivery.new {}
6
+ subject do
7
+ Pousse::RedisDelivery.new {}
8
8
  end
9
9
 
10
10
  describe '#deliver!' do
11
11
 
12
12
  let :redis_instance do
13
- redis_instance = stub()
13
+ redis_instance = stub(quit: true)
14
14
  Redis.stub(new: redis_instance)
15
15
  redis_instance
16
16
  end
@@ -26,14 +26,26 @@ describe Pousse::RedisDelivery do
26
26
  redis_instance
27
27
  .should_receive(:publish)
28
28
  .with('everyone', 'alert("Générale !");')
29
- redis.deliver!(mail)
29
+ subject.deliver!(mail)
30
30
  end
31
31
 
32
32
  it 'does not fail when redis can not connect' do
33
33
  redis_instance.should_receive :publish do
34
34
  raise Redis::CannotConnectError.new 'Error connecting to Redis on 127.0.0.1:6379 (ECONNREFUSED)'
35
35
  end
36
- expect{ redis.deliver!(mail) }.to_not raise_error
36
+ expect{ subject.deliver!(mail) }.to_not raise_error
37
+ end
38
+
39
+ it 'disconnect after sending' do
40
+ redis_instance.should_receive(:quit)
41
+ subject.deliver!(mail)
42
+ end
43
+
44
+ it 'does not crash if Redis.new raise an error' do
45
+ Redis.should_receive(:new) do
46
+ raise Redis::CannotConnectError.new 'Error connecting to Redis on 127.0.0.1:6379 (ECONNREFUSED)'
47
+ end
48
+ subject.deliver!(mail)
37
49
  end
38
50
  end
39
51
  end
data/spec/spec_helper.rb CHANGED
@@ -3,6 +3,9 @@ require 'bundler/setup'
3
3
 
4
4
  require 'pousse'
5
5
 
6
+ require 'coveralls'
7
+ Coveralls.wear!
8
+
6
9
  RSpec.configure do |config|
7
10
  # some (optional) config here
8
11
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pousse
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-06-26 00:00:00.000000000 Z
13
+ date: 2013-09-24 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler
@@ -86,6 +86,8 @@ extra_rdoc_files: []
86
86
  files:
87
87
  - .gitignore
88
88
  - .rspec
89
+ - .ruby-version
90
+ - .travis.yml
89
91
  - Gemfile
90
92
  - LICENSE.txt
91
93
  - README.md
@@ -116,12 +118,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
116
118
  - - ! '>='
117
119
  - !ruby/object:Gem::Version
118
120
  version: '0'
121
+ segments:
122
+ - 0
123
+ hash: 125855808649955746
119
124
  required_rubygems_version: !ruby/object:Gem::Requirement
120
125
  none: false
121
126
  requirements:
122
127
  - - ! '>='
123
128
  - !ruby/object:Gem::Version
124
129
  version: '0'
130
+ segments:
131
+ - 0
132
+ hash: 125855808649955746
125
133
  requirements: []
126
134
  rubyforge_project:
127
135
  rubygems_version: 1.8.23