inboxes 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +10 -0
- data/README.md +5 -0
- data/app/controllers/inboxes/discussions_controller.rb +11 -0
- data/app/models/discussion.rb +5 -3
- data/app/models/message.rb +11 -0
- data/config/locales/en.yml +1 -0
- data/config/locales/ru.yml +1 -0
- data/inboxes.gemspec +3 -1
- data/lib/generators/inboxes/templates/install.rb +1 -1
- data/lib/inboxes/version.rb +1 -1
- data/spec/fake_app.rb +11 -7
- data/spec/inboxes/discussions_controller_spec.rb +96 -96
- data/spec/inboxes/discussions_routing_spec.rb +23 -23
- data/spec/inboxes/message_spec.rb +8 -5
- data/spec/inboxes/messages_controller_spec.rb +42 -42
- data/spec/inboxes/speaker_spec.rb +12 -12
- data/spec/inboxes/speakers_controller_spec.rb +72 -72
- data/spec/spec_helper.rb +6 -8
- data/spec/support/factories.rb +18 -23
- data/spec/support/sequences.rb +35 -0
- data/vendor/assets/javascripts/inboxes/faye/init.js.coffee +1 -1
- metadata +45 -15
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
#Inboxes
|
2
2
|
|
3
|
+
[![Build Status](https://secure.travis-ci.org/evrone/inboxes.png)](http://travis-ci.org/evrone/inboxes)
|
4
|
+
|
3
5
|
Inboxes is a young messaging system for Rails app. It:
|
4
6
|
|
5
7
|
- provides 3 models for developers: Discussion, Message and Speaker
|
@@ -80,9 +82,12 @@ You can read more about that on it's [official page](http://faye.jcoglan.com/).
|
|
80
82
|
##Contributors
|
81
83
|
|
82
84
|
- [Kir Shatrov](https://github.com/kirs/) (Evrone Company)
|
85
|
+
- [Nikolay Seskin](https://github.com/finist/) (Evrone Company)
|
83
86
|
- [Andrey Ognevsky](https://github.com/ognevsy/) (Evrone Company)
|
84
87
|
- [Alexander Brodyanoj](https://github.com/dom1nga)
|
85
88
|
- [Dmitriy Kiriyenko](https://github.com/dmitriy-kiriyenko)
|
86
89
|
- [Alexey Poimtsev](https://github.com/alec-c4) ([http://progress-engine.ru/](Progress Engine))
|
90
|
+
- [isqad88](https://github.com/isqad88/)
|
91
|
+
- [Chris Sargeant](https://github.com/liothen/)
|
87
92
|
|
88
93
|
##Feel free for pull requests!
|
@@ -13,6 +13,17 @@ class Inboxes::DiscussionsController < Inboxes::BaseController
|
|
13
13
|
def new
|
14
14
|
@discussion.messages.build
|
15
15
|
end
|
16
|
+
|
17
|
+
def destroy
|
18
|
+
@discussion.destroy
|
19
|
+
|
20
|
+
flash[:notice] = t("inboxes.discussions.removed")
|
21
|
+
begin
|
22
|
+
redirect_to :back
|
23
|
+
rescue ActionController::RedirectBackError
|
24
|
+
redirect_to discussions_url
|
25
|
+
end
|
26
|
+
end
|
16
27
|
|
17
28
|
def create
|
18
29
|
@discussion.add_recipient_token current_user.id
|
data/app/models/discussion.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
class Discussion < ActiveRecord::Base
|
2
2
|
attr_accessor :recipient_tokens, :recipient_ids
|
3
3
|
attr_reader :recipient_ids
|
4
|
+
attr_accessible :recipient_tokens, :messages_attributes, :user, :recipient_ids
|
4
5
|
|
5
6
|
# creater
|
6
7
|
has_many :messages, :dependent => :destroy
|
@@ -16,6 +17,8 @@ class Discussion < ActiveRecord::Base
|
|
16
17
|
user = user_or_user_id.is_a?(User) ? user_or_user_id.id : user_or_user_id
|
17
18
|
joins(:speakers).where("discussions.updated_at >= speakers.updated_at AND speakers.user_id = ?", user)
|
18
19
|
end)
|
20
|
+
|
21
|
+
default_scope order('updated_at DESC')
|
19
22
|
|
20
23
|
accepts_nested_attributes_for :messages
|
21
24
|
|
@@ -42,7 +45,7 @@ class Discussion < ActiveRecord::Base
|
|
42
45
|
|
43
46
|
def add_speaker(user)
|
44
47
|
raise ArgumentError, "You can add speaker only to existing Discussion. Save your the Discussion object firstly" if new_record?
|
45
|
-
Speaker.create(:discussion => self, :user => user)
|
48
|
+
Speaker.create(:discussion => self, :user => user, :updated_at => self.updated_at)
|
46
49
|
end
|
47
50
|
|
48
51
|
def remove_speaker(user)
|
@@ -92,7 +95,6 @@ class Discussion < ActiveRecord::Base
|
|
92
95
|
|
93
96
|
def mark_as_read_for(user)
|
94
97
|
speaker = Speaker.find_or_create_by_user_id_and_discussion_id(user.id, self.id)
|
95
|
-
# flag.update_attributes(:updat => Time.zone.now)
|
96
98
|
speaker.touch
|
97
99
|
end
|
98
100
|
|
@@ -103,7 +105,7 @@ class Discussion < ActiveRecord::Base
|
|
103
105
|
private
|
104
106
|
|
105
107
|
def check_that_has_at_least_two_users
|
106
|
-
errors.add :recipient_tokens, t("inboxes.discussions.choose_at_least_one_recipient") if !self.recipient_ids || self.recipient_ids.size < 2
|
108
|
+
errors.add :recipient_tokens, I18n.t("inboxes.discussions.choose_at_least_one_recipient") if !self.recipient_ids || self.recipient_ids.size < 2
|
107
109
|
end
|
108
110
|
|
109
111
|
end
|
data/app/models/message.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
class Message < ActiveRecord::Base
|
2
|
+
|
3
|
+
attr_accessible :body, :user, :discussion
|
2
4
|
|
3
5
|
default_scope order(:created_at)
|
4
6
|
|
@@ -12,6 +14,15 @@ class Message < ActiveRecord::Base
|
|
12
14
|
def visible_for? user
|
13
15
|
self.created_at.to_i >= self.discussion.user_invited_at(user).to_i
|
14
16
|
end
|
17
|
+
|
18
|
+
def unread_for? user
|
19
|
+
speaker = self.discussion.find_speaker_by_user(user)
|
20
|
+
if speaker
|
21
|
+
self.created_at.to_i >= speaker.updated_at.to_i
|
22
|
+
else
|
23
|
+
true
|
24
|
+
end
|
25
|
+
end
|
15
26
|
|
16
27
|
private
|
17
28
|
|
data/config/locales/en.yml
CHANGED
@@ -8,6 +8,7 @@ en:
|
|
8
8
|
added: "Speaker was added to discussion"
|
9
9
|
removed: "Speaker was removed from discussion"
|
10
10
|
discussions:
|
11
|
+
removed: "Discussion removed"
|
11
12
|
started: "Discussion started"
|
12
13
|
leaved: "You leave the discussion"
|
13
14
|
already_exists: "Discussion between you and %{user} already exists"
|
data/config/locales/ru.yml
CHANGED
@@ -12,6 +12,7 @@ ru:
|
|
12
12
|
already_exists: "Дискуссия между вами и %{user} уже существует"
|
13
13
|
can_not_participate: "Вы не состоите в этой дискуссии"
|
14
14
|
choose_at_least_one_recipient: "Укажите хотя бы одного получателя"
|
15
|
+
removed: "Переписка удалена"
|
15
16
|
speakers:
|
16
17
|
added: "Собеседник успешно добавлен"
|
17
18
|
removed: "Собеседник удален"
|
data/inboxes.gemspec
CHANGED
@@ -25,9 +25,11 @@ Gem::Specification.new do |s|
|
|
25
25
|
s.add_runtime_dependency "rails"
|
26
26
|
s.add_runtime_dependency "cancan"
|
27
27
|
|
28
|
+
s.add_development_dependency "pg"
|
28
29
|
s.add_development_dependency "sqlite3"
|
29
30
|
s.add_development_dependency 'rspec', ['>= 0']
|
30
|
-
s.add_development_dependency 'factory_girl', ['
|
31
|
+
s.add_development_dependency 'factory_girl', ['< 3.0']
|
32
|
+
s.add_development_dependency 'factory_girl_rails'
|
31
33
|
s.add_development_dependency 'rspec-rails', ['>= 0']
|
32
34
|
# s.add_development_dependency 'rr', ['>= 0']
|
33
35
|
# s.add_development_dependency 'steak', ['>= 0']
|
data/lib/inboxes/version.rb
CHANGED
data/spec/fake_app.rb
CHANGED
@@ -1,17 +1,21 @@
|
|
1
1
|
require 'active_record'
|
2
2
|
require 'action_controller/railtie'
|
3
|
-
require 'action_view/railtie'
|
3
|
+
# require 'action_view/railtie'
|
4
4
|
|
5
|
-
require "cancan"
|
6
|
-
require "cancan/ability"
|
7
|
-
require "cancan/controller_resource"
|
8
|
-
require "cancan/controller_additions"
|
5
|
+
# require "cancan"
|
6
|
+
# require "cancan/ability"
|
7
|
+
# require "cancan/controller_resource"
|
8
|
+
# require "cancan/controller_additions"
|
9
9
|
|
10
10
|
require 'devise'
|
11
11
|
require 'devise/orm/active_record'
|
12
12
|
|
13
13
|
# database
|
14
|
-
|
14
|
+
if ENV['TRAVIS'].present?
|
15
|
+
ActiveRecord::Base.configurations = {'test' => {:adapter => 'postgresql', :database => 'inboxes_test', :username => "postgres"}}
|
16
|
+
else
|
17
|
+
ActiveRecord::Base.configurations = {'test' => {:adapter => 'sqlite3', :database => ':memory:'}}
|
18
|
+
end
|
15
19
|
ActiveRecord::Base.establish_connection('test')
|
16
20
|
|
17
21
|
# config
|
@@ -28,7 +32,7 @@ class User < ActiveRecord::Base
|
|
28
32
|
devise :database_authenticatable, :registerable,
|
29
33
|
:recoverable, :rememberable, :trackable, :validatable
|
30
34
|
attr_accessible :email, :password, :password_confirmation, :remember_me, :name
|
31
|
-
validates :name, :presence => true
|
35
|
+
validates :name, :presence => true
|
32
36
|
has_inboxes
|
33
37
|
end
|
34
38
|
|
@@ -1,96 +1,96 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Inboxes::DiscussionsController do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
end
|
1
|
+
# require 'spec_helper'
|
2
|
+
#
|
3
|
+
# describe Inboxes::DiscussionsController do
|
4
|
+
# context "Guest" do
|
5
|
+
# it "should not see discussions list" do
|
6
|
+
# get :index
|
7
|
+
# response.should redirect_to(sign_in_url)
|
8
|
+
# end
|
9
|
+
#
|
10
|
+
# it "should not see new action" do
|
11
|
+
# get :new
|
12
|
+
# response.should redirect_to(sign_in_url)
|
13
|
+
# end
|
14
|
+
#
|
15
|
+
# it "should not create discussion if model is valid" do
|
16
|
+
# recipient_ids = [Factory(:user).id, Factory(:user).id]
|
17
|
+
# post(:create,
|
18
|
+
# :discussion => {
|
19
|
+
# :recipient_ids => recipient_ids,
|
20
|
+
# :messages_attributes => {
|
21
|
+
# 0 => {:body => Factory.next(:string)}
|
22
|
+
# }
|
23
|
+
# }
|
24
|
+
# )
|
25
|
+
#
|
26
|
+
# response.should redirect_to(sign_in_url)
|
27
|
+
# end
|
28
|
+
#
|
29
|
+
# end
|
30
|
+
#
|
31
|
+
# context("Authenticated admin") do
|
32
|
+
# before(:each) do
|
33
|
+
# @request.env["devise.mapping"] = Devise.mappings[:user]
|
34
|
+
# @user = Factory(:user)
|
35
|
+
# @user.set_role(:admin)
|
36
|
+
# sign_in @user
|
37
|
+
# end
|
38
|
+
#
|
39
|
+
# it "should see discussions list" do
|
40
|
+
# get :index
|
41
|
+
# response.should render_template(:index)
|
42
|
+
# end
|
43
|
+
#
|
44
|
+
# it "should see new action" do
|
45
|
+
# get :new
|
46
|
+
# response.should render_template(:new)
|
47
|
+
# end
|
48
|
+
#
|
49
|
+
# it "should open discussion" do
|
50
|
+
# discussion = Factory.build(:discussion)
|
51
|
+
# discussion.recipient_ids = [@user, Factory(:user)].map { |u| u.id }
|
52
|
+
# discussion.save.should be true
|
53
|
+
#
|
54
|
+
# get(:show, :id => discussion)
|
55
|
+
# response.status.should be 200
|
56
|
+
# end
|
57
|
+
#
|
58
|
+
# it "should create private discussion if model is valid" do
|
59
|
+
# recipient_ids = [Factory(:user).id, Factory(:user).id]
|
60
|
+
# post(:create,
|
61
|
+
# :discussion => {
|
62
|
+
# :recipient_ids => recipient_ids,
|
63
|
+
# :messages_attributes => {
|
64
|
+
# 0 => {:body => Factory.next(:string)}
|
65
|
+
# }
|
66
|
+
# }
|
67
|
+
# )
|
68
|
+
#
|
69
|
+
# response.should redirect_to(discussion_url(assigns[:discussion]))
|
70
|
+
# end
|
71
|
+
#
|
72
|
+
# it "should create group discussion if model is valid" do
|
73
|
+
# recipient_ids = [Factory(:user).id, Factory(:user).id, Factory(:user).id]
|
74
|
+
# post(:create,
|
75
|
+
# :discussion => {
|
76
|
+
# :recipient_ids => recipient_ids,
|
77
|
+
# :messages_attributes => {
|
78
|
+
# 0 => {:body => Factory.next(:string)}
|
79
|
+
# }
|
80
|
+
# }
|
81
|
+
# )
|
82
|
+
#
|
83
|
+
# response.should redirect_to(discussion_url(assigns[:discussion]))
|
84
|
+
# end
|
85
|
+
#
|
86
|
+
# it "should not create discussion with empty message" do
|
87
|
+
# discussion = Discussion.new
|
88
|
+
# discussion.recipient_ids = [Factory(:user).id, Factory(:user).id, Factory(:user).id]
|
89
|
+
# post(:create, :discussion => discussion)
|
90
|
+
#
|
91
|
+
# response.should render_template(:new)
|
92
|
+
# end
|
93
|
+
#
|
94
|
+
# end
|
95
|
+
#
|
96
|
+
# end
|
@@ -1,23 +1,23 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe Inboxes::DiscussionsController do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
end
|
1
|
+
# require "spec_helper"
|
2
|
+
#
|
3
|
+
# describe Inboxes::DiscussionsController do
|
4
|
+
# describe "routing" do
|
5
|
+
#
|
6
|
+
# it "routes to #index" do
|
7
|
+
# get("/discussions").should route_to("inboxes/discussions#index")
|
8
|
+
# end
|
9
|
+
#
|
10
|
+
# it "routes to #new" do
|
11
|
+
# get("/discussions/new").should route_to("inboxes/discussions#new")
|
12
|
+
# end
|
13
|
+
#
|
14
|
+
# it "routes to #show" do
|
15
|
+
# get("/discussions/1").should route_to("inboxes/discussions#show", :id => "1")
|
16
|
+
# end
|
17
|
+
#
|
18
|
+
# it "routes to #create" do
|
19
|
+
# post("/discussions").should route_to("inboxes/discussions#create")
|
20
|
+
# end
|
21
|
+
#
|
22
|
+
# end
|
23
|
+
# end
|
@@ -6,9 +6,7 @@ describe Message do
|
|
6
6
|
old_user = Factory(:user)
|
7
7
|
discussion.add_speaker(old_user)
|
8
8
|
message = Message.create!(:discussion => discussion, :user => old_user, :body => Factory.next(:string))
|
9
|
-
|
10
9
|
sleep 2
|
11
|
-
|
12
10
|
new_user = Factory(:user)
|
13
11
|
discussion.add_speaker(new_user)
|
14
12
|
message.visible_for?(new_user).should be_false
|
@@ -19,9 +17,14 @@ describe Message do
|
|
19
17
|
user = Factory(:user)
|
20
18
|
discussion.add_speaker(user)
|
21
19
|
message = Message.create!(:discussion => discussion, :user => user, :body => Factory.next(:string))
|
22
|
-
|
23
|
-
sleep 5
|
24
|
-
|
20
|
+
sleep 2
|
25
21
|
message.visible_for?(user).should be_true
|
26
22
|
end
|
23
|
+
|
24
|
+
it "new model should be unread for user" do
|
25
|
+
discussion = Factory(:discussion)
|
26
|
+
message = Message.create!(:user => discussion.users.first, :body => Factory.next(:string), :discussion => discussion)
|
27
|
+
sleep 2
|
28
|
+
message.unread_for?(discussion.users.last).should be true
|
29
|
+
end
|
27
30
|
end
|
@@ -1,42 +1,42 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Inboxes::MessagesController do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
end
|
1
|
+
# require 'spec_helper'
|
2
|
+
#
|
3
|
+
# describe Inboxes::MessagesController do
|
4
|
+
#
|
5
|
+
# render_views
|
6
|
+
#
|
7
|
+
# context "Guest" do
|
8
|
+
# it "should redirect guest if he wants to create message" do
|
9
|
+
# discussion = Factory(:discussion)
|
10
|
+
# # puts discussion.id
|
11
|
+
# post :create, :discussion_id => discussion.id
|
12
|
+
# response.should redirect_to(sign_in_url)
|
13
|
+
# end
|
14
|
+
# end
|
15
|
+
#
|
16
|
+
# context "Authenticated admin" do
|
17
|
+
# before(:each) do
|
18
|
+
# @request.env["devise.mapping"] = Devise.mappings[:user]
|
19
|
+
# @admin = Factory(:admin)
|
20
|
+
# @admin.set_role(:admin)
|
21
|
+
# sign_in @admin
|
22
|
+
# end
|
23
|
+
#
|
24
|
+
# it "create action should redirect to discussion when model is valid" do
|
25
|
+
# Message.any_instance.stubs(:valid?).returns(true)
|
26
|
+
# message = Factory(:message)
|
27
|
+
# user = Factory(:user)
|
28
|
+
# discussion = Factory(:discussion, :recipient_ids => [@admin.id, user.id])
|
29
|
+
# post(:create, :discussion_id => discussion.id)
|
30
|
+
# response.should redirect_to(discussion_url(discussion))
|
31
|
+
# end
|
32
|
+
#
|
33
|
+
# # it "create action should assign flash with error message" do
|
34
|
+
# # Comment.any_instance.stubs(:valid?).returns(false)
|
35
|
+
# # first_post = Factory(:post)
|
36
|
+
# # post :create, :post_id => first_post
|
37
|
+
# #
|
38
|
+
# # flash[:notice].should =~ /Введите текст комментария!/i
|
39
|
+
# # end
|
40
|
+
# end
|
41
|
+
#
|
42
|
+
# end
|
@@ -1,16 +1,16 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Speaker do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
4
|
+
it "should create valid model" do
|
5
|
+
speaker = Speaker.new
|
6
|
+
speaker.user = Factory(:user)
|
7
|
+
speaker.discussion = Factory(:discussion)
|
8
|
+
speaker.save.should be true
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should bot create model without discussion" do
|
12
|
+
speaker = Speaker.new
|
13
|
+
speaker.user = Factory(:user)
|
14
|
+
speaker.save.should be false
|
15
|
+
end
|
16
16
|
end
|
@@ -1,72 +1,72 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Inboxes::SpeakersController do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
end
|
1
|
+
# require 'spec_helper'
|
2
|
+
#
|
3
|
+
# describe Inboxes::SpeakersController do
|
4
|
+
#
|
5
|
+
# context("Authenticated admin") do
|
6
|
+
# before(:each) do
|
7
|
+
# @request.env["devise.mapping"] = Devise.mappings[:user]
|
8
|
+
# @user = Factory(:user)
|
9
|
+
# @user.set_role(:admin)
|
10
|
+
# sign_in @user
|
11
|
+
# end
|
12
|
+
#
|
13
|
+
# it "should add speaker to discussion" do
|
14
|
+
# discussion = Factory(:discussion, :recipient_ids => [@user.id, Factory(:user).id])
|
15
|
+
# post(:create,
|
16
|
+
# :discussion_id => discussion,
|
17
|
+
# :speaker => {
|
18
|
+
# :user_id => Factory(:user).id
|
19
|
+
# }
|
20
|
+
# )
|
21
|
+
# response.should redirect_to(discussion_url(discussion))
|
22
|
+
# flash[:notice].should =~ /Собеседник успешно добавлен/i
|
23
|
+
# end
|
24
|
+
#
|
25
|
+
# # it "should not add bad speaker to discussion" do
|
26
|
+
# # discussion = Factory(:discussion)
|
27
|
+
# #
|
28
|
+
# # lambda {
|
29
|
+
# # post(:create,
|
30
|
+
# # :discussion_id => discussion
|
31
|
+
# # )
|
32
|
+
# # }.should raise_error(ActiveRecord::RecordNotFound)
|
33
|
+
# # end
|
34
|
+
# end
|
35
|
+
#
|
36
|
+
# context("User") do
|
37
|
+
# before(:each) do
|
38
|
+
# @request.env["devise.mapping"] = Devise.mappings[:user]
|
39
|
+
# @user = Factory(:user)
|
40
|
+
# @user.set_role(:user)
|
41
|
+
# sign_in @user
|
42
|
+
# end
|
43
|
+
#
|
44
|
+
# it "should add speaker to discussion if he is participant if this discussion" do
|
45
|
+
# Speaker.any_instance.stubs(:valid?).returns(true)
|
46
|
+
# discussion = Factory(:discussion, :recipient_ids => [@user.id, Factory(:user).id])
|
47
|
+
# # puts discussion.can_participate?(@user)
|
48
|
+
# # new_user = Factory(:user)
|
49
|
+
# post(:create,
|
50
|
+
# :discussion_id => discussion,
|
51
|
+
# :speaker => {
|
52
|
+
# :user_id => Factory(:user).id
|
53
|
+
# }
|
54
|
+
# )
|
55
|
+
# response.should redirect_to(discussion_url(discussion))
|
56
|
+
# # response.should redirect_to(root_url)
|
57
|
+
# flash[:notice].should =~ /Собеседник успешно добавлен/i
|
58
|
+
# end
|
59
|
+
#
|
60
|
+
# # дописать спек
|
61
|
+
# it "should not add speaker to discussion if he is not participant if this discussion" do
|
62
|
+
# discussion = Factory(:discussion)
|
63
|
+
# post(:create,
|
64
|
+
# :discussion_id => discussion,
|
65
|
+
# :speaker => {
|
66
|
+
# :user_id => Factory(:user).id
|
67
|
+
# }
|
68
|
+
# )
|
69
|
+
# response.should redirect_to(root_url)
|
70
|
+
# end
|
71
|
+
# end
|
72
|
+
# end
|
data/spec/spec_helper.rb
CHANGED
@@ -3,6 +3,8 @@ $LOAD_PATH.unshift(File.dirname(__FILE__))
|
|
3
3
|
require 'rails'
|
4
4
|
require 'active_record'
|
5
5
|
require 'inboxes'
|
6
|
+
require 'factory_girl'
|
7
|
+
|
6
8
|
# require 'database_cleaner'
|
7
9
|
# Ensure we use 'syck' instead of 'psych' in 1.9.2
|
8
10
|
# RubyGems >= 1.5.0 uses 'psych' on 1.9.2, but
|
@@ -15,15 +17,11 @@ end
|
|
15
17
|
# require 'fake_gem'
|
16
18
|
require 'fake_app'
|
17
19
|
|
18
|
-
require 'rspec/rails'
|
19
20
|
# Requires supporting files with custom matchers and macros, etc,
|
20
21
|
# in ./support/ and its subdirectories.
|
21
22
|
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
22
23
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
# # CreateAllTables.up unless ActiveRecord::Base.connection.table_exists? 'users'
|
28
|
-
# end
|
29
|
-
# end
|
24
|
+
RSpec.configure do |config|
|
25
|
+
config.include Devise::TestHelpers, :type => :controller
|
26
|
+
config.color_enabled = true
|
27
|
+
end
|
data/spec/support/factories.rb
CHANGED
@@ -1,23 +1,18 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
# association :discussion
|
20
|
-
# # user {Factory(:user)}
|
21
|
-
# # discussion {Factory(:discussion)}
|
22
|
-
# end
|
23
|
-
# end
|
1
|
+
FactoryGirl.define do
|
2
|
+
|
3
|
+
factory :user do
|
4
|
+
email { Factory.next(:email) }
|
5
|
+
name 'user'
|
6
|
+
password "foobar"
|
7
|
+
password_confirmation { |u| u.password }
|
8
|
+
end
|
9
|
+
|
10
|
+
factory :discussion do
|
11
|
+
recipient_ids {[Factory(:user).id, Factory(:user).id]}
|
12
|
+
end
|
13
|
+
|
14
|
+
factory :message do
|
15
|
+
association :user
|
16
|
+
association :discussion
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
Factory.sequence :string do |n|
|
2
|
+
"Lorem ipsum #{n}"
|
3
|
+
end
|
4
|
+
|
5
|
+
Factory.sequence :boolean do |n|
|
6
|
+
(n % 2 == 0 ? true : false)
|
7
|
+
end
|
8
|
+
|
9
|
+
Factory.sequence :tag_list do |n|
|
10
|
+
"Tag_#{n}, Tag2_#{n}, Tag3_#{n}"
|
11
|
+
end
|
12
|
+
|
13
|
+
Factory.sequence :integer do |n|
|
14
|
+
n * 20
|
15
|
+
end
|
16
|
+
|
17
|
+
Factory.sequence :email do |n|
|
18
|
+
"email#{n}@example.com"
|
19
|
+
end
|
20
|
+
|
21
|
+
Factory.sequence :url do |n|
|
22
|
+
"http://example.com/#{n}"
|
23
|
+
end
|
24
|
+
|
25
|
+
Factory.sequence :login do |n|
|
26
|
+
"login#{n}"
|
27
|
+
end
|
28
|
+
|
29
|
+
Factory.sequence :password do |n|
|
30
|
+
"password#{n}"
|
31
|
+
end
|
32
|
+
|
33
|
+
Factory.sequence :text do |n|
|
34
|
+
"#{n}. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
|
35
|
+
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
$ ->
|
2
|
-
fayeUrl = window.location.
|
2
|
+
fayeUrl = window.location.protocol + "//" + window.location.hostname + ":9292/faye" # change port for post of your Faye daemon
|
3
3
|
fayeJS = fayeUrl + ".js"
|
4
4
|
$.getScript(fayeJS, (e)->
|
5
5
|
faye = new Faye.Client(fayeUrl)
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: inboxes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 2
|
10
|
+
version: 0.2.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Kir Shatrov
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-
|
18
|
+
date: 2012-04-25 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: haml-rails
|
@@ -74,7 +74,7 @@ dependencies:
|
|
74
74
|
type: :runtime
|
75
75
|
version_requirements: *id004
|
76
76
|
- !ruby/object:Gem::Dependency
|
77
|
-
name:
|
77
|
+
name: pg
|
78
78
|
prerelease: false
|
79
79
|
requirement: &id005 !ruby/object:Gem::Requirement
|
80
80
|
none: false
|
@@ -88,7 +88,7 @@ dependencies:
|
|
88
88
|
type: :development
|
89
89
|
version_requirements: *id005
|
90
90
|
- !ruby/object:Gem::Dependency
|
91
|
-
name:
|
91
|
+
name: sqlite3
|
92
92
|
prerelease: false
|
93
93
|
requirement: &id006 !ruby/object:Gem::Requirement
|
94
94
|
none: false
|
@@ -102,24 +102,38 @@ dependencies:
|
|
102
102
|
type: :development
|
103
103
|
version_requirements: *id006
|
104
104
|
- !ruby/object:Gem::Dependency
|
105
|
-
name:
|
105
|
+
name: rspec
|
106
106
|
prerelease: false
|
107
107
|
requirement: &id007 !ruby/object:Gem::Requirement
|
108
108
|
none: false
|
109
109
|
requirements:
|
110
|
-
- -
|
110
|
+
- - ">="
|
111
111
|
- !ruby/object:Gem::Version
|
112
|
-
hash:
|
112
|
+
hash: 3
|
113
113
|
segments:
|
114
|
-
-
|
115
|
-
|
116
|
-
version: "1.2"
|
114
|
+
- 0
|
115
|
+
version: "0"
|
117
116
|
type: :development
|
118
117
|
version_requirements: *id007
|
119
118
|
- !ruby/object:Gem::Dependency
|
120
|
-
name:
|
119
|
+
name: factory_girl
|
121
120
|
prerelease: false
|
122
121
|
requirement: &id008 !ruby/object:Gem::Requirement
|
122
|
+
none: false
|
123
|
+
requirements:
|
124
|
+
- - <
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
hash: 7
|
127
|
+
segments:
|
128
|
+
- 3
|
129
|
+
- 0
|
130
|
+
version: "3.0"
|
131
|
+
type: :development
|
132
|
+
version_requirements: *id008
|
133
|
+
- !ruby/object:Gem::Dependency
|
134
|
+
name: factory_girl_rails
|
135
|
+
prerelease: false
|
136
|
+
requirement: &id009 !ruby/object:Gem::Requirement
|
123
137
|
none: false
|
124
138
|
requirements:
|
125
139
|
- - ">="
|
@@ -129,7 +143,21 @@ dependencies:
|
|
129
143
|
- 0
|
130
144
|
version: "0"
|
131
145
|
type: :development
|
132
|
-
version_requirements: *
|
146
|
+
version_requirements: *id009
|
147
|
+
- !ruby/object:Gem::Dependency
|
148
|
+
name: rspec-rails
|
149
|
+
prerelease: false
|
150
|
+
requirement: &id010 !ruby/object:Gem::Requirement
|
151
|
+
none: false
|
152
|
+
requirements:
|
153
|
+
- - ">="
|
154
|
+
- !ruby/object:Gem::Version
|
155
|
+
hash: 3
|
156
|
+
segments:
|
157
|
+
- 0
|
158
|
+
version: "0"
|
159
|
+
type: :development
|
160
|
+
version_requirements: *id010
|
133
161
|
description: Messaging system for Rails 3 app
|
134
162
|
email:
|
135
163
|
- shatrov@me.com
|
@@ -142,6 +170,7 @@ extra_rdoc_files: []
|
|
142
170
|
files:
|
143
171
|
- .gitignore
|
144
172
|
- .rspec
|
173
|
+
- .travis.yml
|
145
174
|
- Gemfile
|
146
175
|
- README.md
|
147
176
|
- Rakefile
|
@@ -173,7 +202,6 @@ files:
|
|
173
202
|
- lib/inboxes/engine.rb
|
174
203
|
- lib/inboxes/railtie.rb
|
175
204
|
- lib/inboxes/version.rb
|
176
|
-
- log/development.log
|
177
205
|
- spec/devise_config.rb
|
178
206
|
- spec/fake_app.rb
|
179
207
|
- spec/fake_gem.rb
|
@@ -187,6 +215,7 @@ files:
|
|
187
215
|
- spec/inboxes_spec.rb
|
188
216
|
- spec/spec_helper.rb
|
189
217
|
- spec/support/factories.rb
|
218
|
+
- spec/support/sequences.rb
|
190
219
|
- vendor/assets/javascripts/inboxes/faye.js
|
191
220
|
- vendor/assets/javascripts/inboxes/faye/init.js.coffee
|
192
221
|
homepage: http://evrone.com/
|
@@ -236,3 +265,4 @@ test_files:
|
|
236
265
|
- spec/inboxes_spec.rb
|
237
266
|
- spec/spec_helper.rb
|
238
267
|
- spec/support/factories.rb
|
268
|
+
- spec/support/sequences.rb
|