message_train 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.document +5 -0
- data/.rspec +1 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +7 -0
- data/Gemfile +51 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +83 -0
- data/Rakefile +71 -0
- data/VERSION +1 -0
- data/app/assets/javascripts/message_train.js +138 -0
- data/app/assets/stylesheets/message_train.scss +107 -0
- data/app/controllers/message_train/application_controller.rb +64 -0
- data/app/controllers/message_train/boxes_controller.rb +37 -0
- data/app/controllers/message_train/conversations_controller.rb +38 -0
- data/app/controllers/message_train/messages_controller.rb +74 -0
- data/app/controllers/message_train/participants_controller.rb +36 -0
- data/app/helpers/message_train/application_helper.rb +4 -0
- data/app/helpers/message_train/boxes_helper.rb +30 -0
- data/app/helpers/message_train/conversations_helper.rb +73 -0
- data/app/helpers/message_train/messages_helper.rb +58 -0
- data/app/models/message_train/attachment.rb +17 -0
- data/app/models/message_train/box.rb +268 -0
- data/app/models/message_train/conversation.rb +101 -0
- data/app/models/message_train/ignore.rb +18 -0
- data/app/models/message_train/message.rb +146 -0
- data/app/models/message_train/receipt.rb +70 -0
- data/app/views/application/404.html.haml +3 -0
- data/app/views/message_train/application/results.json.jbuilder +8 -0
- data/app/views/message_train/boxes/_dropdown_list.html.haml +5 -0
- data/app/views/message_train/boxes/_list_item.html.haml +5 -0
- data/app/views/message_train/boxes/_widget.html.haml +6 -0
- data/app/views/message_train/boxes/show.html.haml +47 -0
- data/app/views/message_train/conversations/_conversation.html.haml +9 -0
- data/app/views/message_train/conversations/_deleted_toggle.html.haml +1 -0
- data/app/views/message_train/conversations/_ignored_toggle.html.haml +4 -0
- data/app/views/message_train/conversations/_read_toggle.html.haml +4 -0
- data/app/views/message_train/conversations/_toggle.html.haml +1 -0
- data/app/views/message_train/conversations/_trashed_toggle.html.haml +4 -0
- data/app/views/message_train/conversations/show.html.haml +11 -0
- data/app/views/message_train/conversations/show.json.jbuilder +2 -0
- data/app/views/message_train/messages/_deleted_toggle.html.haml +1 -0
- data/app/views/message_train/messages/_form.html.haml +8 -0
- data/app/views/message_train/messages/_message.html.haml +35 -0
- data/app/views/message_train/messages/_read_toggle.html.haml +4 -0
- data/app/views/message_train/messages/_toggle.html.haml +1 -0
- data/app/views/message_train/messages/_trashed_toggle.html.haml +4 -0
- data/app/views/message_train/messages/edit.html.haml +2 -0
- data/app/views/message_train/messages/new.html.haml +2 -0
- data/app/views/message_train/messages/show.json.jbuilder +2 -0
- data/app/views/message_train/participants/_field.html.haml +4 -0
- data/app/views/message_train/participants/_participant.json.jbuilder +5 -0
- data/app/views/message_train/participants/index.json.jbuilder +3 -0
- data/app/views/message_train/participants/show.json.jbuilder +1 -0
- data/bin/rails +12 -0
- data/config/initializers/bootstrap_pager_config.rb +10 -0
- data/config/initializers/date_time.rb +5 -0
- data/config/locales/en.yml +50 -0
- data/config/routes.rb +11 -0
- data/db/migrate/20150721145319_create_message_train_conversations.rb +9 -0
- data/db/migrate/20150721160322_create_message_train_messages.rb +14 -0
- data/db/migrate/20150721161144_create_message_train_attachments.rb +10 -0
- data/db/migrate/20150721161940_create_message_train_receipts.rb +16 -0
- data/db/migrate/20150721163838_create_message_train_ignores.rb +11 -0
- data/lib/generators/message_train/install/install_generator.rb +30 -0
- data/lib/generators/message_train/install/templates/initializer.rb +10 -0
- data/lib/generators/message_train/utils.rb +16 -0
- data/lib/message_train/configuration.rb +35 -0
- data/lib/message_train/engine.rb +19 -0
- data/lib/message_train/localization.rb +31 -0
- data/lib/message_train/mixin.rb +83 -0
- data/lib/message_train/version.rb +7 -0
- data/lib/message_train.rb +20 -0
- data/lib/tasks/message_train_tasks.rake +0 -0
- data/message_train.gemspec +325 -0
- data/night_train.gemspec +274 -0
- data/spec/controllers/message_train/boxes_controller_spec.rb +82 -0
- data/spec/controllers/message_train/conversations_controller_spec.rb +86 -0
- data/spec/controllers/message_train/messages_controller_spec.rb +210 -0
- data/spec/controllers/message_train/participants_controller_spec.rb +35 -0
- data/spec/dummy/.rspec +2 -0
- data/spec/dummy/Rakefile +6 -0
- data/spec/dummy/app/assets/files/message_train/attachments/1917-Boys_Race_Above-Wiki.jpg +0 -0
- data/spec/dummy/app/assets/files/message_train/attachments/ACD_Silverbarn's_Mayumi.jpg +0 -0
- data/spec/dummy/app/assets/files/message_train/attachments/ACD_obedience.jpg +0 -0
- data/spec/dummy/app/assets/files/message_train/attachments/A_Man_and_His_Dog.jpg +0 -0
- data/spec/dummy/app/assets/files/message_train/attachments/Alaskan_Malamute_agility_a-frame.jpg +0 -0
- data/spec/dummy/app/assets/files/message_train/attachments/American_water_spaniel_02.jpg +0 -0
- data/spec/dummy/app/assets/files/message_train/attachments/Aport_konkurs_rybnik.jpg +0 -0
- data/spec/dummy/app/assets/files/message_train/attachments/Askerhytta.jpg +0 -0
- data/spec/dummy/app/assets/files/message_train/attachments/Bambisj.jpg +0 -0
- data/spec/dummy/app/assets/files/message_train/attachments/Cattle_dog_skating.jpg +0 -0
- data/spec/dummy/app/assets/files/message_train/attachments/Dog's_Olympics_training_ground_-_geograph.org.uk_-_660324.jpg +0 -0
- data/spec/dummy/app/assets/files/message_train/attachments/DogShowHierarchy.png +0 -0
- data/spec/dummy/app/assets/files/message_train/attachments/Dog_weight_pull.jpg +0 -0
- data/spec/dummy/app/assets/files/message_train/attachments/Draghuntpostcard.jpg +0 -0
- data/spec/dummy/app/assets/files/message_train/attachments/Esham_51.JPG +0 -0
- data/spec/dummy/app/assets/files/message_train/attachments/FastCourseExample.jpg +0 -0
- data/spec/dummy/app/assets/files/message_train/attachments/Fotos_joel_141.JPG +0 -0
- data/spec/dummy/app/assets/files/message_train/attachments/Galgo_Spanish_male_brindle.jpg +0 -0
- data/spec/dummy/app/assets/files/message_train/attachments/Golden-retriever-carlos-bei-der-dummyarbeit.jpg +0 -0
- data/spec/dummy/app/assets/files/message_train/attachments/Habavk.jpg +0 -0
- data/spec/dummy/app/assets/files/message_train/attachments/Haie_rci.svg +1714 -0
- data/spec/dummy/app/assets/files/message_train/attachments/Hanging_18.jpg +0 -0
- data/spec/dummy/app/assets/files/message_train/attachments/Hundewa.jpg +0 -0
- data/spec/dummy/app/assets/files/message_train/attachments/K9ProSports_AttackOnHandler.jpg +0 -0
- data/spec/dummy/app/assets/files/message_train/attachments/K9ProSports_heel.jpg +0 -0
- data/spec/dummy/app/assets/files/message_train/attachments/K9Pro_Civil_agitation.JPG +0 -0
- data/spec/dummy/app/assets/files/message_train/attachments/TrainingSchutzhundRetrieveOverWall.jpg +0 -0
- data/spec/dummy/app/assets/files/message_train/attachments/example.pdf +0 -0
- data/spec/dummy/app/assets/files/message_train/attachments/letterlegal5.doc +0 -0
- data/spec/dummy/app/assets/files/message_train/attachments/pdf-sample.pdf +0 -0
- data/spec/dummy/app/assets/files/message_train/attachments/sample.pdf +0 -0
- data/spec/dummy/app/assets/files/message_train/attachments/tips.doc +0 -0
- data/spec/dummy/app/assets/files/message_train/attachments/wd-spectools-word-sample-04.doc +0 -0
- data/spec/dummy/app/assets/images/logo.svg +140 -0
- data/spec/dummy/app/assets/javascripts/application.js +17 -0
- data/spec/dummy/app/assets/stylesheets/application.css.scss +35 -0
- data/spec/dummy/app/controllers/application_controller.rb +14 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/mailers/.keep +0 -0
- data/spec/dummy/app/models/.keep +0 -0
- data/spec/dummy/app/models/group.rb +19 -0
- data/spec/dummy/app/models/role.rb +10 -0
- data/spec/dummy/app/models/user.rb +23 -0
- data/spec/dummy/app/views/layouts/_top_navigation.html.haml +5 -0
- data/spec/dummy/app/views/layouts/application.html.haml +29 -0
- data/spec/dummy/bin/bundle +3 -0
- data/spec/dummy/bin/rails +4 -0
- data/spec/dummy/bin/rake +4 -0
- data/spec/dummy/bin/setup +29 -0
- data/spec/dummy/config/application.rb +40 -0
- data/spec/dummy/config/boot.rb +5 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +41 -0
- data/spec/dummy/config/environments/production.rb +79 -0
- data/spec/dummy/config/environments/test.rb +42 -0
- data/spec/dummy/config/initializers/assets.rb +11 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/bootstrap_leather.rb +7 -0
- data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
- data/spec/dummy/config/initializers/devise.rb +265 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy/config/initializers/inflections.rb +16 -0
- data/spec/dummy/config/initializers/message_train.rb +10 -0
- data/spec/dummy/config/initializers/mime_types.rb +4 -0
- data/spec/dummy/config/initializers/paperclip.rb +2 -0
- data/spec/dummy/config/initializers/rolify.rb +7 -0
- data/spec/dummy/config/initializers/session_store.rb +3 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/devise.en.yml +60 -0
- data/spec/dummy/config/locales/en.yml +23 -0
- data/spec/dummy/config/routes.rb +5 -0
- data/spec/dummy/config/secrets.yml +22 -0
- data/spec/dummy/config/unused/temporary_i18n_debugging.rb +12 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/db/migrate/20150721140013_devise_create_users.rb +42 -0
- data/spec/dummy/db/migrate/20150721141009_rolify_create_roles.rb +19 -0
- data/spec/dummy/db/migrate/20150721141128_create_groups.rb +11 -0
- data/spec/dummy/db/migrate/20150721150307_add_display_name_column_to_users.rb +6 -0
- data/spec/dummy/db/migrate/20150724142846_create_message_train_conversations.night_train.rb +10 -0
- data/spec/dummy/db/migrate/20150724142847_create_message_train_messages.night_train.rb +15 -0
- data/spec/dummy/db/migrate/20150724142848_create_message_train_attachments.night_train.rb +11 -0
- data/spec/dummy/db/migrate/20150724142849_create_message_train_receipts.night_train.rb +17 -0
- data/spec/dummy/db/migrate/20150724142850_create_message_train_ignores.night_train.rb +12 -0
- data/spec/dummy/db/schema.rb +121 -0
- data/spec/dummy/db/seeds/conversations.seeds.rb +86 -0
- data/spec/dummy/db/seeds/development/conversations.seeds.rb +9 -0
- data/spec/dummy/db/seeds/groups.seeds.rb +9 -0
- data/spec/dummy/db/seeds/test/conversations.seeds.rb +9 -0
- data/spec/dummy/db/seeds/users.seeds.rb +15 -0
- data/spec/dummy/db/seeds.rb +0 -0
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/lib/assets/.keep +0 -0
- data/spec/dummy/log/.keep +0 -0
- data/spec/dummy/public/404.html +67 -0
- data/spec/dummy/public/422.html +67 -0
- data/spec/dummy/public/500.html +66 -0
- data/spec/dummy/public/capybara.html +193 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/factories/attachment.rb +6 -0
- data/spec/factories/group.rb +20 -0
- data/spec/factories/message.rb +68 -0
- data/spec/factories/user.rb +8 -0
- data/spec/features/boxes_spec.rb +50 -0
- data/spec/features/conversations_spec.rb +36 -0
- data/spec/features/messages_spec.rb +53 -0
- data/spec/helpers/message_train/boxes_helper_spec.rb +44 -0
- data/spec/message_train_spec.rb +7 -0
- data/spec/models/group_spec.rb +23 -0
- data/spec/models/message_train/attachment_spec.rb +12 -0
- data/spec/models/message_train/box_spec.rb +195 -0
- data/spec/models/message_train/conversation_spec.rb +98 -0
- data/spec/models/message_train/ignore_spec.rb +27 -0
- data/spec/models/message_train/message_spec.rb +83 -0
- data/spec/models/message_train/receipt_spec.rb +73 -0
- data/spec/models/user_spec.rb +68 -0
- data/spec/rails_helper.rb +83 -0
- data/spec/spec_helper.rb +92 -0
- data/spec/support/controller_behaviors.rb +88 -0
- data/spec/support/controller_macros.rb +13 -0
- data/spec/support/conversations.rb +10 -0
- data/spec/support/factory_girl.rb +3 -0
- data/spec/support/feature_behaviors.rb +62 -0
- data/spec/support/groups.rb +3 -0
- data/spec/support/loaded_site.rb +5 -0
- data/spec/support/shared_connection.rb +13 -0
- data/spec/support/users.rb +6 -0
- data/spec/support/utilities.rb +8 -0
- data/vendor/assets/javascripts/bootstrap-tags.js +623 -0
- data/vendor/assets/stylesheets/bootstrap-tags.css +78 -0
- metadata +608 -0
@@ -0,0 +1,83 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
module MessageTrain
|
4
|
+
RSpec.describe Message do
|
5
|
+
include_context 'loaded site'
|
6
|
+
describe 'Model' do
|
7
|
+
# Relationships
|
8
|
+
it { should belong_to :conversation }
|
9
|
+
it { should belong_to :sender }
|
10
|
+
it { should have_many :attachments }
|
11
|
+
it { should have_many :receipts }
|
12
|
+
|
13
|
+
# Validations
|
14
|
+
it { should validate_presence_of :sender }
|
15
|
+
it { should validate_presence_of :subject }
|
16
|
+
end
|
17
|
+
describe 'Callbacks' do
|
18
|
+
context 'sets draft to true on a message to no one' do
|
19
|
+
subject { draft_conversation.messages.drafts.first }
|
20
|
+
its(:sender) { should eq first_user }
|
21
|
+
its(:receipts) { should have_exactly(1).item } # i.e. sender
|
22
|
+
its(:recipients) { should be_empty }
|
23
|
+
its(:draft) { should be true }
|
24
|
+
end
|
25
|
+
context 'generates receipts when present' do
|
26
|
+
subject { sent_conversation.messages.first }
|
27
|
+
its(:sender) { should eq first_user }
|
28
|
+
its(:receipts) { should have_exactly(2).items } # i.e. sender and recipient
|
29
|
+
its(:recipients) { should include second_user }
|
30
|
+
its(:draft) { should be false }
|
31
|
+
end
|
32
|
+
end
|
33
|
+
describe 'Scopes and Methods' do
|
34
|
+
context '.drafts' do
|
35
|
+
subject { MessageTrain::Message.drafts.first.conversation }
|
36
|
+
it { should eq draft_conversation }
|
37
|
+
end
|
38
|
+
context '.by' do
|
39
|
+
subject { MessageTrain::Message.by(first_user) }
|
40
|
+
it { should include sent_conversation.messages.first }
|
41
|
+
it { should include draft_conversation.messages.first }
|
42
|
+
end
|
43
|
+
context '.drafts_by' do
|
44
|
+
subject { MessageTrain::Message.drafts_by(first_user).first.conversation }
|
45
|
+
it { should eq draft_conversation }
|
46
|
+
end
|
47
|
+
context '.with_receipts_by' do
|
48
|
+
subject { MessageTrain::Message.with_receipts_by(first_user).last.conversation }
|
49
|
+
it { should eq sent_conversation }
|
50
|
+
end
|
51
|
+
context '.with_receipts_to' do
|
52
|
+
subject { MessageTrain::Message.with_receipts_to(first_user).last.conversation }
|
53
|
+
it { should eq unread_conversation }
|
54
|
+
end
|
55
|
+
context '.with_trashed_to and #is_trashed_to?' do
|
56
|
+
subject { trashed_conversation.messages.with_trashed_to(first_user).first.is_trashed_to?(first_user) }
|
57
|
+
it { should be true }
|
58
|
+
end
|
59
|
+
context '.with_deleted_to and #is_deleted_to?' do
|
60
|
+
subject { deleted_conversation.messages.with_deleted_to(first_user).first.is_deleted_to?(first_user) }
|
61
|
+
it { should be true }
|
62
|
+
end
|
63
|
+
context '.with_read_to and #is_read_to?' do
|
64
|
+
subject { read_conversation.messages.with_read_to(first_user).first.is_read_to?(first_user) }
|
65
|
+
it { should be true }
|
66
|
+
end
|
67
|
+
context '.mark' do
|
68
|
+
before do
|
69
|
+
read_conversation.messages.mark(:trash, first_user)
|
70
|
+
end
|
71
|
+
subject { read_conversation.messages.first.is_trashed_to?(first_user) }
|
72
|
+
it { should be true }
|
73
|
+
end
|
74
|
+
context '#mark' do
|
75
|
+
before do
|
76
|
+
read_conversation.messages.first.mark(:unread, first_user)
|
77
|
+
end
|
78
|
+
subject { read_conversation.messages.first.is_read_to?(first_user) }
|
79
|
+
it { should be false }
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
module MessageTrain
|
4
|
+
RSpec.describe Receipt do
|
5
|
+
describe 'Model' do
|
6
|
+
# Relationships
|
7
|
+
it { should belong_to :message }
|
8
|
+
it { should belong_to :recipient }
|
9
|
+
# Validations
|
10
|
+
it { should validate_presence_of :message }
|
11
|
+
it { should validate_presence_of :recipient }
|
12
|
+
end
|
13
|
+
describe 'Scopes and Methods' do
|
14
|
+
include_context 'loaded site'
|
15
|
+
describe '.sender_receipt' do
|
16
|
+
subject { MessageTrain::Receipt.sender_receipt.first }
|
17
|
+
its(:sender) { should be true }
|
18
|
+
end
|
19
|
+
describe '.recipient_receipt' do
|
20
|
+
subject { MessageTrain::Receipt.recipient_receipt.first }
|
21
|
+
its(:sender) { should be false }
|
22
|
+
end
|
23
|
+
describe '.for' do
|
24
|
+
subject { MessageTrain::Receipt.for(first_user).conversations }
|
25
|
+
it { should include sent_conversation }
|
26
|
+
it { should include unread_conversation }
|
27
|
+
it { should include ignored_conversation }
|
28
|
+
it { should include trashed_conversation }
|
29
|
+
it { should include read_conversation }
|
30
|
+
end
|
31
|
+
describe '.receipts_to' do
|
32
|
+
subject { MessageTrain::Receipt.receipts_to(first_user) }
|
33
|
+
its(:first) { should be_a MessageTrain::Receipt }
|
34
|
+
its(:count) { should be > 5 }
|
35
|
+
end
|
36
|
+
describe '.trashed_to' do
|
37
|
+
subject { MessageTrain::Receipt.trashed_to(first_user).first.message.conversation }
|
38
|
+
its(:subject) { should eq 'Trashed Conversation' }
|
39
|
+
end
|
40
|
+
describe '.untrashed_to' do
|
41
|
+
subject { MessageTrain::Receipt.untrashed_to(first_user).first }
|
42
|
+
its(:marked_trash) { should be false }
|
43
|
+
end
|
44
|
+
describe '.read_to' do
|
45
|
+
subject { MessageTrain::Receipt.read_to(first_user).first.message.conversation }
|
46
|
+
its(:subject) { should eq 'Read Conversation' }
|
47
|
+
end
|
48
|
+
describe '.deleted_to' do
|
49
|
+
subject { MessageTrain::Receipt.deleted_to(first_user).first.message.conversation }
|
50
|
+
its(:subject) { should eq 'Deleted Conversation' }
|
51
|
+
end
|
52
|
+
describe '.undeleted_to' do
|
53
|
+
subject { MessageTrain::Receipt.undeleted_to(first_user).first }
|
54
|
+
its(:marked_deleted) { should be false }
|
55
|
+
end
|
56
|
+
describe '.message_ids' do
|
57
|
+
subject { MessageTrain::Receipt.receipts_by(first_user).message_ids }
|
58
|
+
it { should include sent_conversation.messages.first.id }
|
59
|
+
end
|
60
|
+
describe '.messages' do
|
61
|
+
subject { MessageTrain::Receipt.receipts_by(first_user).messages }
|
62
|
+
it { should include sent_conversation.messages.first }
|
63
|
+
end
|
64
|
+
describe '#mark' do
|
65
|
+
before do
|
66
|
+
unread_conversation.messages.first.receipts.for(first_user).first.mark(:read)
|
67
|
+
end
|
68
|
+
subject { unread_conversation.messages.first.is_read_to?(first_user) }
|
69
|
+
it { should be true }
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
RSpec.describe User do
|
4
|
+
|
5
|
+
describe 'Model' do
|
6
|
+
# Rolify Gem by extension
|
7
|
+
it { should have_and_belong_to_many(:roles) }
|
8
|
+
|
9
|
+
# MessageTrain Gem
|
10
|
+
it { should have_many(:messages) }
|
11
|
+
it { should have_many(:receipts) }
|
12
|
+
end
|
13
|
+
|
14
|
+
describe 'Scopes and Methods' do
|
15
|
+
include_context 'loaded site'
|
16
|
+
|
17
|
+
describe '#conversations' do
|
18
|
+
context 'with division as :in' do
|
19
|
+
subject { first_user.conversations(:in).first.includes_receipts_to?(first_user) }
|
20
|
+
it { should be true }
|
21
|
+
end
|
22
|
+
context 'with division as :sent' do
|
23
|
+
subject { first_user.conversations(:sent).first.includes_receipts_by?(first_user) }
|
24
|
+
it { should be true }
|
25
|
+
end
|
26
|
+
context 'with division as :trash' do
|
27
|
+
subject { first_user.conversations(:trash).first.includes_trashed_for?(first_user) }
|
28
|
+
it { should be true}
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe '#all_boxes' do
|
33
|
+
context 'returns all boxes for the given user' do
|
34
|
+
subject { first_user.all_boxes }
|
35
|
+
its(:first) { should be_a MessageTrain::Box }
|
36
|
+
its(:count) { should be 6 }
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe '#all_conversations' do
|
41
|
+
context 'returns all conversations with any receipt' do
|
42
|
+
subject { first_user.all_conversations }
|
43
|
+
it { should include sent_conversation }
|
44
|
+
it { should include unread_conversation }
|
45
|
+
it { should include read_conversation }
|
46
|
+
it { should include ignored_conversation }
|
47
|
+
it { should include trashed_conversation }
|
48
|
+
it { should include deleted_conversation }
|
49
|
+
it { should_not include someone_elses_conversation }
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe '#all_messages' do
|
54
|
+
context 'returns all messages with any receipt' do
|
55
|
+
subject { first_user.all_messages }
|
56
|
+
it { should include sent_conversation.messages.first }
|
57
|
+
it { should include unread_conversation.messages.first }
|
58
|
+
it { should include read_conversation.messages.first }
|
59
|
+
it { should include ignored_conversation.messages.first }
|
60
|
+
it { should include trashed_conversation.messages.first }
|
61
|
+
it { should include deleted_conversation.messages.first }
|
62
|
+
it { should_not include someone_elses_conversation.messages.first }
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
require 'coveralls'
|
2
|
+
Coveralls.wear!
|
3
|
+
# This file is copied to spec/ when you run 'rails generate rspec:install'
|
4
|
+
ENV['RAILS_ENV'] ||= 'test'
|
5
|
+
require File.expand_path('../dummy/config/environment', __FILE__)
|
6
|
+
# Prevent database truncation if the environment is production
|
7
|
+
abort("The Rails environment is running in production mode!") if Rails.env.production?
|
8
|
+
require 'spec_helper'
|
9
|
+
require 'rspec/rails'
|
10
|
+
# Add additional requires below this line. Rails is not loaded until this point!
|
11
|
+
require 'shoulda/matchers'
|
12
|
+
require 'factory_girl_rails'
|
13
|
+
require 'capybara/rspec'
|
14
|
+
require 'database_cleaner'
|
15
|
+
require 'rake'
|
16
|
+
|
17
|
+
# Requires supporting ruby files with custom matchers and macros, etc, in
|
18
|
+
# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
|
19
|
+
# run as spec files by default. This means that files in spec/support that end
|
20
|
+
# in _spec.rb will both be required and run as specs, causing the specs to be
|
21
|
+
# run twice. It is recommended that you do not name files matching this glob to
|
22
|
+
# end with _spec.rb. You can configure this pattern with the --pattern
|
23
|
+
# option on the command line or in ~/.rspec, .rspec or `.rspec-local`.
|
24
|
+
#
|
25
|
+
# The following line is provided for convenience purposes. It has the downside
|
26
|
+
# of increasing the boot-up time by auto-requiring all files in the support
|
27
|
+
# directory. Alternatively, in the individual `*_spec.rb` files, manually
|
28
|
+
# require only the support files necessary.
|
29
|
+
#
|
30
|
+
Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }
|
31
|
+
|
32
|
+
# Checks for pending migrations before tests are run.
|
33
|
+
# If you are not using ActiveRecord, you can remove this line.
|
34
|
+
ActiveRecord::Migrator.migrations_paths = 'spec/dummy/db/migrate'
|
35
|
+
ActiveRecord::Migration.maintain_test_schema!
|
36
|
+
|
37
|
+
RSpec.configure do |config|
|
38
|
+
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
|
39
|
+
# config.fixture_path = "#{::Rails.root}/spec/fixtures"
|
40
|
+
|
41
|
+
# If you're not using ActiveRecord, or you'd prefer not to run each of your
|
42
|
+
# examples within a transaction, remove the following line or assign false
|
43
|
+
# instead of true.
|
44
|
+
config.use_transactional_fixtures = false
|
45
|
+
|
46
|
+
config.before(:suite) do
|
47
|
+
DatabaseCleaner.strategy = :transaction
|
48
|
+
DatabaseCleaner.clean_with(:truncation)
|
49
|
+
Dummy::Application.load_tasks
|
50
|
+
Rake::Task['db:seed'].invoke # loading seeds
|
51
|
+
end
|
52
|
+
config.around(:each) do |example|
|
53
|
+
DatabaseCleaner.cleaning do
|
54
|
+
example.run
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
# RSpec Rails can automatically mix in different behaviours to your tests
|
59
|
+
# based on their file location, for example enabling you to call `get` and
|
60
|
+
# `post` in specs under `spec/controllers`.
|
61
|
+
#
|
62
|
+
# You can disable this behaviour by removing the line below, and instead
|
63
|
+
# explicitly tag your specs with their type, e.g.:
|
64
|
+
#
|
65
|
+
# RSpec.describe UsersController, :type => :controller do
|
66
|
+
# # ...
|
67
|
+
# end
|
68
|
+
#
|
69
|
+
# The different available types are documented in the features, such as in
|
70
|
+
# https://relishapp.com/rspec/rspec-rails/docs
|
71
|
+
config.infer_spec_type_from_file_location!
|
72
|
+
|
73
|
+
config.expect_with(:rspec) { |c| c.syntax = [:should, :expect] }
|
74
|
+
|
75
|
+
config.before(:each) { @routes = MessageTrain::Engine.routes }
|
76
|
+
config.include MessageTrain::Engine.routes.url_helpers
|
77
|
+
|
78
|
+
config.include Warden::Test::Helpers
|
79
|
+
config.include Devise::TestHelpers, type: :controller
|
80
|
+
config.include Devise::TestHelpers, type: :helper
|
81
|
+
config.include Devise::TestHelpers, type: :routing
|
82
|
+
config.include RSpecHtmlMatchers
|
83
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
# This file was generated by the `rails generate rspec:install` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# The generated `.rspec` file contains `--require spec_helper` which will cause
|
4
|
+
# this file to always be loaded, without a need to explicitly require it in any
|
5
|
+
# files.
|
6
|
+
#
|
7
|
+
# Given that it is always loaded, you are encouraged to keep this file as
|
8
|
+
# light-weight as possible. Requiring heavyweight dependencies from this file
|
9
|
+
# will add to the boot time of your test suite on EVERY test run, even for an
|
10
|
+
# individual file that may not need all of that loaded. Instead, consider making
|
11
|
+
# a separate helper file that requires the additional dependencies and performs
|
12
|
+
# the additional setup, and require it from the spec files that actually need
|
13
|
+
# it.
|
14
|
+
#
|
15
|
+
# The `.rspec` file also contains a few flags that are not defaults but that
|
16
|
+
# users commonly want.
|
17
|
+
#
|
18
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
19
|
+
RSpec.configure do |config|
|
20
|
+
# rspec-expectations config goes here. You can use an alternate
|
21
|
+
# assertion/expectation library such as wrong or the stdlib/minitest
|
22
|
+
# assertions if you prefer.
|
23
|
+
config.expect_with :rspec do |expectations|
|
24
|
+
# This option will default to `true` in RSpec 4. It makes the `description`
|
25
|
+
# and `failure_message` of custom matchers include text for helper methods
|
26
|
+
# defined using `chain`, e.g.:
|
27
|
+
# be_bigger_than(2).and_smaller_than(4).description
|
28
|
+
# # => "be bigger than 2 and smaller than 4"
|
29
|
+
# ...rather than:
|
30
|
+
# # => "be bigger than 2"
|
31
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
32
|
+
end
|
33
|
+
|
34
|
+
# rspec-mocks config goes here. You can use an alternate test double
|
35
|
+
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
36
|
+
config.mock_with :rspec do |mocks|
|
37
|
+
# Prevents you from mocking or stubbing a method that does not exist on
|
38
|
+
# a real object. This is generally recommended, and will default to
|
39
|
+
# `true` in RSpec 4.
|
40
|
+
mocks.verify_partial_doubles = true
|
41
|
+
end
|
42
|
+
|
43
|
+
# The settings below are suggested to provide a good initial experience
|
44
|
+
# with RSpec, but feel free to customize to your heart's content.
|
45
|
+
=begin
|
46
|
+
# These two settings work together to allow you to limit a spec run
|
47
|
+
# to individual examples or groups you care about by tagging them with
|
48
|
+
# `:focus` metadata. When nothing is tagged with `:focus`, all examples
|
49
|
+
# get run.
|
50
|
+
config.filter_run :focus
|
51
|
+
config.run_all_when_everything_filtered = true
|
52
|
+
|
53
|
+
# Allows RSpec to persist some state between runs in order to support
|
54
|
+
# the `--only-failures` and `--next-failure` CLI options. We recommend
|
55
|
+
# you configure your source control system to ignore this file.
|
56
|
+
config.example_status_persistence_file_path = "spec/examples.txt"
|
57
|
+
|
58
|
+
# Limits the available syntax to the non-monkey patched syntax that is
|
59
|
+
# recommended. For more details, see:
|
60
|
+
# - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
|
61
|
+
# - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
62
|
+
# - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
|
63
|
+
config.disable_monkey_patching!
|
64
|
+
|
65
|
+
# Many RSpec users commonly either run the entire suite or an individual
|
66
|
+
# file, and it's useful to allow more verbose output when running an
|
67
|
+
# individual spec file.
|
68
|
+
if config.files_to_run.one?
|
69
|
+
# Use the documentation formatter for detailed output,
|
70
|
+
# unless a formatter has already been configured
|
71
|
+
# (e.g. via a command-line flag).
|
72
|
+
config.default_formatter = 'doc'
|
73
|
+
end
|
74
|
+
|
75
|
+
# Print the 10 slowest examples and example groups at the
|
76
|
+
# end of the spec run, to help surface which specs are running
|
77
|
+
# particularly slow.
|
78
|
+
config.profile_examples = 10
|
79
|
+
|
80
|
+
# Run specs in random order to surface order dependencies. If you find an
|
81
|
+
# order dependency and want to debug it, you can fix the order by providing
|
82
|
+
# the seed, which is printed after each run.
|
83
|
+
# --seed 1234
|
84
|
+
config.order = :random
|
85
|
+
|
86
|
+
# Seed global randomization in this process using the `--seed` CLI option.
|
87
|
+
# Setting this allows you to use `--seed` to deterministically reproduce
|
88
|
+
# test failures related to randomization by passing the same `--seed` value
|
89
|
+
# as the one that triggered the failure.
|
90
|
+
Kernel.srand config.seed
|
91
|
+
=end
|
92
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
shared_examples_for 'a successful page' do |options = {}|
|
2
|
+
context 'responds successfully' do
|
3
|
+
subject { response }
|
4
|
+
it { should be_success }
|
5
|
+
end
|
6
|
+
if options[:which_renders].present?
|
7
|
+
it_behaves_like 'a page rendering a template', options[:which_renders]
|
8
|
+
end
|
9
|
+
end
|
10
|
+
shared_examples_for 'a page rendering a template' do |template|
|
11
|
+
context "renders the #{template} template" do
|
12
|
+
subject { response }
|
13
|
+
it { should render_template(template) }
|
14
|
+
end
|
15
|
+
end
|
16
|
+
shared_examples_for 'an error response' do |http_status|
|
17
|
+
context "issues error response code #{http_status}" do
|
18
|
+
subject { response }
|
19
|
+
it { should have_http_status(http_status) }
|
20
|
+
end
|
21
|
+
end
|
22
|
+
shared_examples_for 'a redirect to' do |path|
|
23
|
+
context "redirects to #{path}" do
|
24
|
+
subject { response }
|
25
|
+
it { should redirect_to path_to_url(path) }
|
26
|
+
end
|
27
|
+
end
|
28
|
+
shared_examples_for 'a redirect matching' do |path_expression|
|
29
|
+
context "redirects matching #{path_expression}" do
|
30
|
+
subject { response.location }
|
31
|
+
it { should match path_expression }
|
32
|
+
end
|
33
|
+
end
|
34
|
+
shared_examples_for 'a redirect to sign in' do
|
35
|
+
it_behaves_like 'a redirect to', '/users/sign_in'
|
36
|
+
end
|
37
|
+
shared_examples_for 'an error response with message' do |message|
|
38
|
+
it_behaves_like 'an error response', :forbidden
|
39
|
+
context 'sets failure message' do
|
40
|
+
subject { flash[:error] }
|
41
|
+
it { should eq message }
|
42
|
+
end
|
43
|
+
end
|
44
|
+
shared_examples_for 'a 404 Not Found error' do
|
45
|
+
it_behaves_like 'an error response', :not_found
|
46
|
+
it_behaves_like 'a page rendering a template', '404'
|
47
|
+
end
|
48
|
+
shared_examples_for 'a page with a message' do |options|
|
49
|
+
it_behaves_like 'a successful page'
|
50
|
+
options.each do |key, value|
|
51
|
+
context "sets #{key.to_s} message" do
|
52
|
+
subject { flash[key] }
|
53
|
+
it { should eq value }
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
shared_examples_for 'a page with an error message' do |message|
|
58
|
+
it_behaves_like 'a page with a message', error: message
|
59
|
+
end
|
60
|
+
shared_examples_for 'a page with an alert message' do |message|
|
61
|
+
it_behaves_like 'a page with a message', alert: message
|
62
|
+
end
|
63
|
+
shared_examples_for 'a page with a notice message' do |message|
|
64
|
+
it_behaves_like 'a page with a message', notice: message
|
65
|
+
end
|
66
|
+
shared_examples_for 'a 403 Forbidden error' do
|
67
|
+
it_should_behave_like 'an error response with message', 'You are not authorized to access this page.'
|
68
|
+
end
|
69
|
+
shared_examples_for 'a redirect with notice' do |path, message|
|
70
|
+
it_behaves_like 'a redirect to', path
|
71
|
+
context 'sets notice' do
|
72
|
+
subject { flash[:notice] }
|
73
|
+
it { should eq message }
|
74
|
+
end
|
75
|
+
end
|
76
|
+
shared_examples_for 'a redirect with alert' do |path, message|
|
77
|
+
it_behaves_like 'a redirect to', path
|
78
|
+
context 'sets alert' do
|
79
|
+
subject { flash[:alert] }
|
80
|
+
it { should eq message }
|
81
|
+
end
|
82
|
+
end
|
83
|
+
shared_examples_for 'a response without error' do
|
84
|
+
context 'sets no errors' do
|
85
|
+
subject { flash[:error] }
|
86
|
+
it { should be nil }
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
shared_context 'conversations' do
|
2
|
+
let(:sent_conversation) { MessageTrain::Conversation.find_by_subject('Sent Conversation') }
|
3
|
+
let(:unread_conversation) { MessageTrain::Conversation.find_by_subject('Unread Conversation') }
|
4
|
+
let(:ignored_conversation) { MessageTrain::Conversation.find_by_subject('Ignored Conversation') }
|
5
|
+
let(:trashed_conversation) { MessageTrain::Conversation.find_by_subject('Trashed Conversation') }
|
6
|
+
let(:read_conversation) { MessageTrain::Conversation.find_by_subject('Read Conversation') }
|
7
|
+
let(:deleted_conversation) { MessageTrain::Conversation.find_by_subject('Deleted Conversation') }
|
8
|
+
let(:someone_elses_conversation) { MessageTrain::Conversation.find_by_subject("Someone Else's Conversation") }
|
9
|
+
let(:draft_conversation) { MessageTrain::Conversation.find_by_subject('This should turn into a draft')}
|
10
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
shared_examples_for 'a bootstrap page' do |options = {}|
|
2
|
+
include ERB::Util
|
3
|
+
context 'displays a page with bootstrap elements' do
|
4
|
+
subject { page }
|
5
|
+
if options[:title].present?
|
6
|
+
it { should have_title html_escape(options[:title]) }
|
7
|
+
it { should have_xpath '//h1', text: options[:title] }
|
8
|
+
end
|
9
|
+
it { should have_selector '.navbar .navbar-header .navbar-brand', text: BootstrapLeather.configuration.application_title }
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
shared_examples_for 'a bootstrap page with a dropdown navigation list' do |options|
|
14
|
+
if options[:text]
|
15
|
+
it { should have_selector 'li.dropdown a.dropdown-toggle', text: options[:text]}
|
16
|
+
else
|
17
|
+
it { should have_selector 'li.dropdown a.dropdown-toggle'}
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
shared_examples_for 'a bootstrap page with an alert' do |type, text|
|
22
|
+
subject { page }
|
23
|
+
it { should have_selector ".alert.alert-#{type}", text: text }
|
24
|
+
end
|
25
|
+
|
26
|
+
shared_examples_for 'a bootstrap page without an alert' do |type|
|
27
|
+
subject { page }
|
28
|
+
it { should_not have_selector ".alert.alert-#{type}" }
|
29
|
+
end
|
30
|
+
|
31
|
+
shared_examples_for 'a bootstrap page listing a collection of items' do |object, options={}|
|
32
|
+
options[:minimum] ||= 1
|
33
|
+
options[:plural_title] ||= object.model_name.human.pluralize(2)
|
34
|
+
options[:plural_name] ||= object.table_name
|
35
|
+
collection_css_id = options[:plural_name]
|
36
|
+
member_css_class = options[:plural_name].singularize
|
37
|
+
it_behaves_like 'a bootstrap page', title: options[:plural_title].titlecase
|
38
|
+
context "displays a list of ##{collection_css_id} in .#{member_css_class}" do
|
39
|
+
subject { page }
|
40
|
+
it { should have_css("##{collection_css_id} .#{member_css_class}", minimum: options[:minimum]) }
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
shared_examples_for 'a bootstrap page showing an item' do |object, title, options={}|
|
45
|
+
options[:css_id] ||= object.table_name.singularize
|
46
|
+
it_behaves_like 'a bootstrap page', title: title
|
47
|
+
context "displays an item at ##{options[:css_id]}" do
|
48
|
+
subject { page }
|
49
|
+
it { should have_css("##{options[:css_id]}") }
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
shared_examples_for 'a bootstrap form with errors' do |error_fields|
|
54
|
+
subject { page }
|
55
|
+
for field in error_fields
|
56
|
+
it_behaves_like 'a bootstrap page with an alert', 'danger', "#{field.to_s.humanize} can't be blank"
|
57
|
+
context 'shows which field has errors' do
|
58
|
+
subject { page }
|
59
|
+
it { should have_css('.form-group.has-error', text: field.to_s.humanize)}
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# In your test_helper.rb
|
2
|
+
class ActiveRecord::Base
|
3
|
+
mattr_accessor :shared_connection
|
4
|
+
@@shared_connection = nil
|
5
|
+
|
6
|
+
def self.connection
|
7
|
+
@@shared_connection || retrieve_connection
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
# Forces all threads to share the same connection. This works on
|
12
|
+
# Capybara because it starts the web server in a thread.
|
13
|
+
ActiveRecord::Base.shared_connection = ActiveRecord::Base.connection
|