introspective_grape 0.0.3
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.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.travis.yml +35 -0
- data/Gemfile +15 -0
- data/MIT-LICENSE +20 -0
- data/README.md +103 -0
- data/Rakefile +26 -0
- data/app/assets/images/introspective_grape/.keep +0 -0
- data/app/assets/stylesheets/introspective_grape/.keep +0 -0
- data/app/controllers/.keep +0 -0
- data/app/helpers/.keep +0 -0
- data/app/mailers/.keep +0 -0
- data/app/models/.keep +0 -0
- data/app/views/.keep +0 -0
- data/bin/rails +12 -0
- data/introspective_grape.gemspec +49 -0
- data/lib/introspective_grape/api.rb +445 -0
- data/lib/introspective_grape/camel_snake.rb +71 -0
- data/lib/introspective_grape/version.rb +3 -0
- data/lib/introspective_grape.rb +4 -0
- data/lib/tasks/introspective_grape_tasks.rake +4 -0
- data/spec/dummy/Gemfile +4 -0
- data/spec/dummy/README.rdoc +28 -0
- data/spec/dummy/Rakefile +6 -0
- data/spec/dummy/app/api/active_record_helpers.rb +17 -0
- data/spec/dummy/app/api/api_helpers.rb +36 -0
- data/spec/dummy/app/api/dummy/chat_api.rb +108 -0
- data/spec/dummy/app/api/dummy/company_api.rb +8 -0
- data/spec/dummy/app/api/dummy/entities.rb +25 -0
- data/spec/dummy/app/api/dummy/location_api.rb +37 -0
- data/spec/dummy/app/api/dummy/project_api.rb +51 -0
- data/spec/dummy/app/api/dummy/role_api.rb +7 -0
- data/spec/dummy/app/api/dummy/sessions.rb +55 -0
- data/spec/dummy/app/api/dummy/user_api.rb +32 -0
- data/spec/dummy/app/api/dummy_api.rb +57 -0
- data/spec/dummy/app/api/error_handlers.rb +28 -0
- data/spec/dummy/app/api/permissions_helper.rb +7 -0
- data/spec/dummy/app/assets/images/.keep +0 -0
- data/spec/dummy/app/assets/javascripts/application.js +13 -0
- data/spec/dummy/app/assets/stylesheets/application.css +15 -0
- data/spec/dummy/app/controllers/application_controller.rb +5 -0
- data/spec/dummy/app/controllers/concerns/.keep +0 -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/abstract_adapter.rb +13 -0
- data/spec/dummy/app/models/admin_user.rb +6 -0
- data/spec/dummy/app/models/chat.rb +18 -0
- data/spec/dummy/app/models/chat_message.rb +34 -0
- data/spec/dummy/app/models/chat_message_user.rb +17 -0
- data/spec/dummy/app/models/chat_user.rb +16 -0
- data/spec/dummy/app/models/company.rb +14 -0
- data/spec/dummy/app/models/concerns/.keep +0 -0
- data/spec/dummy/app/models/image.rb +21 -0
- data/spec/dummy/app/models/job.rb +10 -0
- data/spec/dummy/app/models/locatable.rb +6 -0
- data/spec/dummy/app/models/location.rb +26 -0
- data/spec/dummy/app/models/location_beacon.rb +16 -0
- data/spec/dummy/app/models/location_gps.rb +14 -0
- data/spec/dummy/app/models/project.rb +20 -0
- data/spec/dummy/app/models/project_job.rb +7 -0
- data/spec/dummy/app/models/role.rb +30 -0
- data/spec/dummy/app/models/super_user.rb +11 -0
- data/spec/dummy/app/models/team.rb +9 -0
- data/spec/dummy/app/models/team_user.rb +13 -0
- data/spec/dummy/app/models/user/chatter.rb +79 -0
- data/spec/dummy/app/models/user.rb +84 -0
- data/spec/dummy/app/models/user_location.rb +28 -0
- data/spec/dummy/app/models/user_project_job.rb +16 -0
- data/spec/dummy/app/policies/application_policy.rb +47 -0
- data/spec/dummy/app/policies/chat_policy.rb +22 -0
- data/spec/dummy/app/policies/company_policy.rb +32 -0
- data/spec/dummy/app/policies/location_policy.rb +29 -0
- data/spec/dummy/app/policies/project_policy.rb +42 -0
- data/spec/dummy/app/policies/role_policy.rb +33 -0
- data/spec/dummy/app/policies/user_location_policy.rb +12 -0
- data/spec/dummy/app/policies/user_policy.rb +8 -0
- data/spec/dummy/app/views/layouts/application.html.erb +13 -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 +38 -0
- data/spec/dummy/config/boot.rb +6 -0
- data/spec/dummy/config/database.yml +23 -0
- data/spec/dummy/config/environment.rb +11 -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 +43 -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/cookies_serializer.rb +3 -0
- data/spec/dummy/config/initializers/devise.rb +262 -0
- data/spec/dummy/config/initializers/devise_async.rb +2 -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/mime_types.rb +4 -0
- data/spec/dummy/config/initializers/paperclip.rb +13 -0
- data/spec/dummy/config/initializers/paperclip_adapter.rb +13 -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 +8 -0
- data/spec/dummy/config/secrets.yml +22 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/db/migrate/20141002205024_devise_create_users.rb +42 -0
- data/spec/dummy/db/migrate/20141002211055_devise_create_admin_users.rb +48 -0
- data/spec/dummy/db/migrate/20141002211057_create_active_admin_comments.rb +19 -0
- data/spec/dummy/db/migrate/20141002220722_add_lockable_to_users.rb +8 -0
- data/spec/dummy/db/migrate/20150406213646_create_companies.rb +11 -0
- data/spec/dummy/db/migrate/20150414213154_add_user_authentication_token.rb +11 -0
- data/spec/dummy/db/migrate/20150415222005_create_roles.rb +12 -0
- data/spec/dummy/db/migrate/20150505181635_create_chats.rb +9 -0
- data/spec/dummy/db/migrate/20150505181636_create_chat_users.rb +11 -0
- data/spec/dummy/db/migrate/20150505181640_create_chat_messages.rb +11 -0
- data/spec/dummy/db/migrate/20150507191529_create_chat_message_users.rb +11 -0
- data/spec/dummy/db/migrate/20150601200526_create_locations.rb +12 -0
- data/spec/dummy/db/migrate/20150601200533_create_locatables.rb +10 -0
- data/spec/dummy/db/migrate/20150601212924_create_location_beacons.rb +15 -0
- data/spec/dummy/db/migrate/20150601213542_create_location_gps.rb +12 -0
- data/spec/dummy/db/migrate/20150609201823_create_user_locations.rb +14 -0
- data/spec/dummy/db/migrate/20150616205336_add_role_user_constraint.rb +9 -0
- data/spec/dummy/db/migrate/20150617232519_create_projects.rb +10 -0
- data/spec/dummy/db/migrate/20150617232521_create_jobs.rb +9 -0
- data/spec/dummy/db/migrate/20150617232522_create_project_jobs.rb +11 -0
- data/spec/dummy/db/migrate/20150623170133_create_user_project_jobs.rb +12 -0
- data/spec/dummy/db/migrate/20150701234929_create_teams.rb +11 -0
- data/spec/dummy/db/migrate/20150701234930_create_team_users.rb +11 -0
- data/spec/dummy/db/migrate/20150727214950_add_confirmable_to_devise.rb +11 -0
- data/spec/dummy/db/migrate/20150820190524_add_user_names.rb +6 -0
- data/spec/dummy/db/migrate/20150824215701_create_images.rb +15 -0
- data/spec/dummy/db/migrate/20150909225019_add_password_to_project.rb +5 -0
- data/spec/dummy/db/schema.rb +278 -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/favicon.ico +0 -0
- data/spec/fixtures/images/avatar.jpeg +0 -0
- data/spec/fixtures/images/exif.jpeg +0 -0
- data/spec/models/chat_spec.rb +32 -0
- data/spec/models/image_spec.rb +14 -0
- data/spec/models/locatable_spec.rb +10 -0
- data/spec/models/project_spec.rb +17 -0
- data/spec/models/role_spec.rb +63 -0
- data/spec/models/team_spec.rb +17 -0
- data/spec/models/team_user_spec.rb +20 -0
- data/spec/models/user_location_spec.rb +35 -0
- data/spec/models/user_project_job_spec.rb +30 -0
- data/spec/models/user_spec.rb +125 -0
- data/spec/rails_helper.rb +23 -0
- data/spec/requests/chat_api_spec.rb +174 -0
- data/spec/requests/company_api_spec.rb +61 -0
- data/spec/requests/location_api_spec.rb +96 -0
- data/spec/requests/project_api_spec.rb +151 -0
- data/spec/requests/role_api_spec.rb +37 -0
- data/spec/requests/sessions_api_spec.rb +55 -0
- data/spec/requests/user_api_spec.rb +191 -0
- data/spec/support/blueprints.rb +103 -0
- data/spec/support/location_helper.rb +56 -0
- data/spec/support/pundit_helpers.rb +13 -0
- data/spec/support/request_helpers.rb +22 -0
- metadata +562 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
require 'rails_helper'
|
|
2
|
+
|
|
3
|
+
RSpec.describe UserLocation, type: :model do
|
|
4
|
+
include LocationHelper
|
|
5
|
+
before :all do
|
|
6
|
+
create_test_airport
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
let(:user) { User.make! }
|
|
10
|
+
|
|
11
|
+
it "validates the detectable type" do
|
|
12
|
+
ul = UserLocation.new(user: user, location: Location.last, detectable: Location.last, coords: rand_coords)
|
|
13
|
+
ul.valid?.should == false
|
|
14
|
+
ul.errors[:detectable_type].should == ["is not included in the list"]
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it "logs a user's locations by beacon" do
|
|
18
|
+
beacon = LocationBeacon.last
|
|
19
|
+
p1 = user.user_locations.build(location: beacon.location, detectable: beacon, coords: rand_coords)
|
|
20
|
+
user.save.should == true
|
|
21
|
+
p2 = user.user_locations.build(location: beacon.location, detectable: beacon, coords: rand_coords)
|
|
22
|
+
user.save.should == true
|
|
23
|
+
user.user_locations.first.should == p2
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
it "logs a user's beacon location by gps" do
|
|
27
|
+
gps = LocationGps.last
|
|
28
|
+
p1 = user.user_locations.build(location: gps.location, detectable: gps, coords: rand_coords)
|
|
29
|
+
user.save.should == true
|
|
30
|
+
p2 = user.user_locations.build(location: gps.location, detectable: gps, coords: rand_coords)
|
|
31
|
+
user.save.should == true
|
|
32
|
+
user.user_locations.first.should == p2
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
require 'rails_helper'
|
|
2
|
+
|
|
3
|
+
RSpec.describe UserProjectJob, type: :model do
|
|
4
|
+
|
|
5
|
+
it "should delegate user name" do
|
|
6
|
+
UserProjectJob.make.name.should_not == nil
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
it "should delegate user email" do
|
|
10
|
+
UserProjectJob.make.email.should_not == nil
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
it "should delegate job title" do
|
|
14
|
+
UserProjectJob.make.title.should_not == nil
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it "should scope job options by project" do
|
|
18
|
+
ProjectJob.make!
|
|
19
|
+
ProjectJob.make!
|
|
20
|
+
|
|
21
|
+
p = Project.make!
|
|
22
|
+
j = Job.make!
|
|
23
|
+
p.jobs.push j
|
|
24
|
+
p.save
|
|
25
|
+
r = UserProjectJob.make!(project: p, job: j)
|
|
26
|
+
UserProjectJob.options_for_job(p).should == p.jobs
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
end
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
require 'rails_helper'
|
|
2
|
+
include ActionDispatch::TestProcess # -> fixture_file_upload
|
|
3
|
+
|
|
4
|
+
RSpec.describe User, type: :model do
|
|
5
|
+
context 'User::Chatter' do
|
|
6
|
+
|
|
7
|
+
def user(email)
|
|
8
|
+
User.find_by_email(email) || User.make!(email: email)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
it "uploads an avatar to AWS" do
|
|
12
|
+
u = User.make
|
|
13
|
+
u.avatar = Image.new(file: fixture_file_upload( Rails.root+'../fixtures/images/exif.jpeg'))
|
|
14
|
+
u.save
|
|
15
|
+
u.avatar.file_processing?.should == false
|
|
16
|
+
|
|
17
|
+
#u.avatar_url.should =~ /medium\/exif.jpeg/
|
|
18
|
+
#u.avatar_url(:original).should =~ /original\/exif.jpeg/
|
|
19
|
+
#u.avatar_url(:thumb).should =~ /thumb\/exif.jpeg/
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
context "chatting" do
|
|
23
|
+
let(:sender) { user('sender@springshot.com') }
|
|
24
|
+
let(:target) { user('target1@springshot.com') }
|
|
25
|
+
let(:target2) { user('target2@springshot.com') }
|
|
26
|
+
let(:target3) { user('target3@springshot.com') }
|
|
27
|
+
|
|
28
|
+
let(:discussion) {
|
|
29
|
+
c = sender.chat([target,target2], 'Hey guys')
|
|
30
|
+
target2.reply( c, "What's up?")
|
|
31
|
+
c
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
before :all do
|
|
36
|
+
Chat.destroy_all
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
it "chatting a user returns a chat" do
|
|
40
|
+
c = sender.chat(target, 'a private message')
|
|
41
|
+
c.kind_of?(Chat).should be_truthy
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
it "a user sees that she has new messages in a discussion" do
|
|
45
|
+
discussion.save! # invoke create hooks on ChatMessage for ChatMessageUser
|
|
46
|
+
sender.new_messages?(discussion)[discussion.id].should == 1
|
|
47
|
+
target2.new_messages?(discussion)[discussion.id].should == 0
|
|
48
|
+
target.new_messages?(discussion)[discussion.id].should == 2
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
it "a user gets notifications for all new messages for all conversations" do
|
|
52
|
+
discussion.save!
|
|
53
|
+
chat2 = target.chat( [target2], "Come to E2")
|
|
54
|
+
target.reply( chat2, "Hurry")
|
|
55
|
+
|
|
56
|
+
target2.new_messages?[discussion.id].should == nil
|
|
57
|
+
target2.new_messages?[chat2.id].should == 2
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
it "a user sees her new messages" do
|
|
61
|
+
discussion.save!
|
|
62
|
+
|
|
63
|
+
sender.read_messages.size.should == 1
|
|
64
|
+
sender.read_messages[0].message.should == "What's up?"
|
|
65
|
+
|
|
66
|
+
target.read_messages.size.should == 2
|
|
67
|
+
target.read_messages(discussion)[0].message.should == "Hey guys"
|
|
68
|
+
target.read_messages(discussion)[1].message.should == "What's up?"
|
|
69
|
+
|
|
70
|
+
target2.read_messages.size.should == 0
|
|
71
|
+
#target2.new_messages[0].message.should == "Hey guys"
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
it "users are notified when a new user is added to the chat" do
|
|
75
|
+
target2.add_chatters(discussion, target3)
|
|
76
|
+
|
|
77
|
+
sender.messages.last.message.should =~ /ADDED_USER/
|
|
78
|
+
target.messages.last.message.should =~ /ADDED_USER/
|
|
79
|
+
target2.messages.last.message.should =~ /ADDED_USER/
|
|
80
|
+
target3.messages.last.message.should =~ /ADDED_USER/
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
it "when a user drops out should not see subsequent messages" do
|
|
84
|
+
discussion.active_users.size.should == 3
|
|
85
|
+
target.leave_chat(discussion).should == true
|
|
86
|
+
# and if the user has left leaving again should register as a success
|
|
87
|
+
target.leave_chat(discussion).should == true
|
|
88
|
+
discussion.active_users.size.should == 2
|
|
89
|
+
sender.reply(discussion, 'I never liked target anyway.')
|
|
90
|
+
|
|
91
|
+
sender.messages.last.message.should == 'I never liked target anyway.'
|
|
92
|
+
target2.messages.last.message.should == 'I never liked target anyway.'
|
|
93
|
+
|
|
94
|
+
target.messages.last.message.should_not == 'I never liked target anyway.'
|
|
95
|
+
target.messages.last.message.should =~ /DEPARTS/
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
it "a user rejoins a chat and doesn't see messages while they were gone" do
|
|
99
|
+
target2.leave_chat(discussion)
|
|
100
|
+
sender.reply(discussion, "Where'd target2 go?")
|
|
101
|
+
sender.add_chatters( discussion, target2)
|
|
102
|
+
|
|
103
|
+
messages = target2.messages.order('created_at').map(&:message)
|
|
104
|
+
messages.include?("Where'd target2 go?").should be_falsey
|
|
105
|
+
messages.last.should =~ /ADDED_USER/
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
it "when a user reads a message it should mark the message as read" do
|
|
109
|
+
discussion.save!
|
|
110
|
+
target.chat_message_users.unread.size.should == 2
|
|
111
|
+
target.mark_messages_as_read(target.messages)
|
|
112
|
+
target.chat_message_users.unread.size.should == 0
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
it "should cascade deletes to chat_user, messages, and read logs" do
|
|
116
|
+
ChatUser.where(discussion.id).size.should == 3
|
|
117
|
+
ChatMessage.where(discussion.id).size.should == 2
|
|
118
|
+
discussion.destroy
|
|
119
|
+
ChatUser.where(discussion.id).size.should == 0
|
|
120
|
+
ChatMessage.where(discussion.id).size.should == 0
|
|
121
|
+
end
|
|
122
|
+
end
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
ENV["RAILS_ENV"] ||= 'test'
|
|
2
|
+
require File.expand_path("../dummy/config/environment", __FILE__)
|
|
3
|
+
require 'rspec/rails'
|
|
4
|
+
require 'support/request_helpers'
|
|
5
|
+
require 'support/pundit_helpers'
|
|
6
|
+
Dir[Rails.root.join("../support/**/*.rb")].each { |f| require f }
|
|
7
|
+
|
|
8
|
+
#load "#{Rails.root}/db/schema.rb"
|
|
9
|
+
RSpec.configure do |config|
|
|
10
|
+
config.include Devise::TestHelpers, type: :controller
|
|
11
|
+
config.use_transactional_fixtures = true
|
|
12
|
+
config.infer_spec_type_from_file_location!
|
|
13
|
+
config.expect_with(:rspec) { |c| c.syntax = :should }
|
|
14
|
+
|
|
15
|
+
# load helpers for the API tests
|
|
16
|
+
config.include RequestHelpers, type: :request
|
|
17
|
+
config.before(:each, type: :request) do
|
|
18
|
+
# run all requests as super user, test permissions under policies
|
|
19
|
+
with_authentication
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
end
|
|
23
|
+
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
require "rails_helper"
|
|
2
|
+
describe Dummy::ChatAPI, type: :request do
|
|
3
|
+
|
|
4
|
+
before :all do
|
|
5
|
+
User.destroy_all
|
|
6
|
+
@without_authentication = true
|
|
7
|
+
|
|
8
|
+
@current_user = User.make!(email: "current_user@springshot.com")
|
|
9
|
+
@sender = User.make!(email: "sender@springshot.com")
|
|
10
|
+
@lurker = User.make!(email: "lurker@springshot.com")
|
|
11
|
+
|
|
12
|
+
@lurk = @sender.chat( @lurker, "Private conversation.")
|
|
13
|
+
@lurker.reply(@lurk, "the lurker has his own conversation that we don't want the current_user to see anywhere")
|
|
14
|
+
|
|
15
|
+
@pm = @sender.chat( @current_user, "Private conversation.")
|
|
16
|
+
@sender.reply(@pm, "I'm asking a question?")
|
|
17
|
+
@sender.reply(@pm, "you there?")
|
|
18
|
+
|
|
19
|
+
@chat = @sender.chat( [@lurker,@current_user], "We need to talk.")
|
|
20
|
+
@current_user.reply(@chat, "Is this about tough love?")
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
context "while current_user is the current user" do
|
|
24
|
+
|
|
25
|
+
before :each do
|
|
26
|
+
@chat.reload
|
|
27
|
+
Grape::Endpoint.before_each do |endpoint|
|
|
28
|
+
allow(endpoint).to receive(:current_user) { @current_user }
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
it "should return a list of a user's chats" do
|
|
33
|
+
get "/api/v1/chats"
|
|
34
|
+
response.should be_success
|
|
35
|
+
json.size.should == 2
|
|
36
|
+
json.first['creator_id'].to_i.should == @sender.id
|
|
37
|
+
json.first['users'].size.should == Chat.find(json.first['id']).users.size
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
context :notifications do
|
|
41
|
+
it "should get new chat notifications" do
|
|
42
|
+
get "/api/v1/chats/notifications/"
|
|
43
|
+
response.should be_success
|
|
44
|
+
json.keys.size.should == 1
|
|
45
|
+
json[@pm.id.to_s].should == 3
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
it "should get new chat notifications for a particular chat" do
|
|
49
|
+
get "/api/v1/chats/notifications/", id: @pm.id
|
|
50
|
+
response.should be_success
|
|
51
|
+
json[@pm.id.to_s].should == 3
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
it "should return 0 for non-existent chats" do
|
|
55
|
+
get "/api/v1/chats/notifications/", id: 0
|
|
56
|
+
response.should be_success
|
|
57
|
+
json['0'].should == 0
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
context :messages do
|
|
62
|
+
|
|
63
|
+
it "should get no new chat messages if user was last to reply" do
|
|
64
|
+
get "/api/v1/chats/messages", id: @chat.id, new: true
|
|
65
|
+
response.should be_success
|
|
66
|
+
json.size.should == 0
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
it "should get new chat messages if user recieves another reply" do
|
|
70
|
+
@sender.reply(@chat, "And now for something completely different.")
|
|
71
|
+
get "/api/v1/chats/messages", id: @chat.id, new: true
|
|
72
|
+
response.should be_success
|
|
73
|
+
json.size.should == 1
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
it "should mark all new messages from all chats as read if mark_as_read is true" do
|
|
77
|
+
@sender.reply(@chat, 'A new response.')
|
|
78
|
+
@current_user.new_messages?.keys.size.should == 2
|
|
79
|
+
get "/api/v1/chats/messages", new: true, mark_as_read: true
|
|
80
|
+
response.should be_success
|
|
81
|
+
json.size.should == 4
|
|
82
|
+
@current_user.new_messages?.keys.size.should == 0
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
context :users do
|
|
88
|
+
it "should list the users in a chat" do
|
|
89
|
+
get "/api/v1/chats/users", id: @chat.id
|
|
90
|
+
response.should be_success
|
|
91
|
+
json.size.should == 3
|
|
92
|
+
json.map{|u| u['email']}.sort.should == [ "current_user@springshot.com", "lurker@springshot.com", "sender@springshot.com" ]
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
it "should add a new user to a chat" do
|
|
96
|
+
new_user1 = User.make
|
|
97
|
+
new_user1.save!
|
|
98
|
+
post "/api/v1/chats/users", id: @chat.id, user_ids: new_user1.id
|
|
99
|
+
response.should be_success
|
|
100
|
+
json['status'].should == true
|
|
101
|
+
@chat.reload
|
|
102
|
+
@chat.active_users.include?(new_user1).should == true
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
it "should add new users to a chat" do
|
|
106
|
+
new_user1 = User.make
|
|
107
|
+
new_user2 = User.make
|
|
108
|
+
new_user1.save!
|
|
109
|
+
new_user2.save!
|
|
110
|
+
post "/api/v1/chats/users", id: @chat.id, user_ids: "#{new_user1.id},#{new_user2.id}"
|
|
111
|
+
response.should be_success
|
|
112
|
+
json['status'].should == true
|
|
113
|
+
@chat.reload
|
|
114
|
+
@chat.active_users.include?(new_user1).should == true
|
|
115
|
+
@chat.active_users.include?(new_user2).should == true
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
it "should be invalid to add an already active chat member to a chat" do
|
|
119
|
+
@chat.chat_users.size.should == 3
|
|
120
|
+
post "/api/v1/chats/users", id: @chat.id, user_ids: @chat.active_users.first.id
|
|
121
|
+
response.status.should == 400
|
|
122
|
+
json['error'].should == "#{@chat.active_users.first.name} is already present in this chat."
|
|
123
|
+
@chat.reload
|
|
124
|
+
@chat.chat_users.size.should == 3
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
it "should raise an error when an outsider tries to add themselves to a chat" do
|
|
128
|
+
post "/api/v1/chats/users", id: @lurk.id, user_ids: @current_user.id
|
|
129
|
+
response.status.should == 400
|
|
130
|
+
json['error'].should == 'Only current chat participants can add users.'
|
|
131
|
+
@lurk.reload
|
|
132
|
+
@lurk.active_users.include?(@current_user).should == false
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
context :chat do
|
|
138
|
+
it "should start a new chat" do
|
|
139
|
+
post "/api/v1/chats", user_ids:@lurker.id, message: 'a new chat'
|
|
140
|
+
response.should be_success
|
|
141
|
+
json['creator_id'].should == @current_user.id
|
|
142
|
+
Chat.last.creator.should == @current_user
|
|
143
|
+
Chat.last.messages.map(&:message).first.should == 'a new chat'
|
|
144
|
+
@lurker.read_messages(Chat.last.id ).last.message.should == 'a new chat'
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
it "should reply to a chat" do
|
|
148
|
+
put "/api/v1/chats/#{@chat.id}", message: 'A reply.'
|
|
149
|
+
response.should be_success
|
|
150
|
+
ChatMessage.last.author.should == @current_user
|
|
151
|
+
@sender.read_messages(Chat.last.id ).last.message.should == 'A reply.'
|
|
152
|
+
@lurker.read_messages(Chat.last.id ).last.message.should == 'A reply.'
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
it "should leave a chat" do
|
|
156
|
+
delete "/api/v1/chats/#{@chat.id}"
|
|
157
|
+
response.should be_success
|
|
158
|
+
json['status'].should == true
|
|
159
|
+
@chat.reload
|
|
160
|
+
@chat.active_users.include?(@current_user).should == false
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
it "should only allow chat participants to reply" do
|
|
164
|
+
@current_user.leave_chat(@chat)
|
|
165
|
+
@current_user.reload
|
|
166
|
+
put "/api/v1/chats/#{@chat.id}", message: "I'm an interloper"
|
|
167
|
+
response.status.should == 400
|
|
168
|
+
json['error'].should == 'Messages: is invalid'
|
|
169
|
+
@chat.messages.last.should_not == "I'm an interloper"
|
|
170
|
+
end
|
|
171
|
+
end
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
end
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
require 'rails_helper'
|
|
2
|
+
|
|
3
|
+
describe Dummy::CompanyAPI, type: :request do
|
|
4
|
+
before :all do
|
|
5
|
+
Company.find_by_name("Sprockets") || Company.make!(name:"Sprockets")
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
let(:company) { Company.find_by_name("Sprockets") }
|
|
9
|
+
|
|
10
|
+
it "should return a list of companies" do
|
|
11
|
+
get '/api/v1/companies'
|
|
12
|
+
response.should be_success
|
|
13
|
+
json.length.should > 0
|
|
14
|
+
json.map{|c| c['id'].to_i}.include?(company.id).should == true
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it "should return the specified company" do
|
|
18
|
+
get "/api/v1/companies/#{company.id}"
|
|
19
|
+
response.should be_success
|
|
20
|
+
json['name'].should == company.name
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it "should return an error if the company doesn't exist" do
|
|
24
|
+
get "/api/v1/companies/#{Company.last.id+1}"
|
|
25
|
+
response.code.should == "404"
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
it "should create a company" do
|
|
30
|
+
post "/api/v1/companies", { name: 'Test 123', short_name: 'T123' }
|
|
31
|
+
response.should be_success
|
|
32
|
+
json['name'].should == "Test 123"
|
|
33
|
+
json['short_name'].should == "T123"
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
it "should validate a new company" do
|
|
37
|
+
post "/api/v1/companies", { name: 'a'*257, short_name: 'a'*11 }
|
|
38
|
+
response.code.should == "400"
|
|
39
|
+
json['error'].should == "Name: is too long (maximum is 256 characters), Short Name: is too long (maximum is 10 characters)"
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
it "should update the company" do
|
|
44
|
+
new_name = 'New Test 1234'
|
|
45
|
+
put "/api/v1/companies/#{company.id}", { name: new_name }
|
|
46
|
+
response.should be_success
|
|
47
|
+
company.reload
|
|
48
|
+
company.name.should == new_name
|
|
49
|
+
json['name'].should == new_name
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
it "should validate the company on update" do
|
|
53
|
+
old_name = company.name
|
|
54
|
+
put "/api/v1/companies/#{company.id}", { name: 'a'*257, short_name: 'a'*11 }
|
|
55
|
+
response.code.should == "400"
|
|
56
|
+
company.reload
|
|
57
|
+
company.name.should == old_name
|
|
58
|
+
json['error'].should == "Name: is too long (maximum is 256 characters), Short Name: is too long (maximum is 10 characters)"
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
end
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
require 'rails_helper'
|
|
2
|
+
|
|
3
|
+
describe Dummy::LocationAPI, type: :request do
|
|
4
|
+
include LocationHelper
|
|
5
|
+
|
|
6
|
+
let(:location) { Location.find_by_name("TEST") }
|
|
7
|
+
|
|
8
|
+
before :all do
|
|
9
|
+
create_test_airport
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
it "should return a list of top level locations and their children" do
|
|
13
|
+
get '/api/v1/locations'
|
|
14
|
+
response.should be_success
|
|
15
|
+
json.length.should > 0
|
|
16
|
+
json.map{|l| l['id'].to_i }.include?(location.id).should == true
|
|
17
|
+
|
|
18
|
+
json.first['child_locations'].size.should > 0
|
|
19
|
+
json.first['child_locations'].map{|l| l['id'].to_i}.sort.should == location.child_locations.map(&:id).sort
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it "should return the specified location" do
|
|
23
|
+
get "/api/v1/locations/#{location.id}"
|
|
24
|
+
response.should be_success
|
|
25
|
+
json['name'].should == location.name
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it "should return an error if the location doesn't exist" do
|
|
29
|
+
get "/api/v1/locations/#{Location.last.id+1}"
|
|
30
|
+
response.code.should == "404"
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
it "should create a location" do
|
|
34
|
+
post "/api/v1/locations", { name: 'Test 123', kind: "terminal" }
|
|
35
|
+
response.should be_success
|
|
36
|
+
json['name'].should == "Test 123"
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
it "should create a location with a beacon" do
|
|
40
|
+
b = LocationBeacon.make(company: Company.last)
|
|
41
|
+
post "/api/v1/locations", { name: 'Test 123', kind: "gate", beacons_attributes: [ b.attributes ] }
|
|
42
|
+
response.should be_success
|
|
43
|
+
json['name'].should == "Test 123"
|
|
44
|
+
l = Location.find(json['id'])
|
|
45
|
+
created = l.beacons.first
|
|
46
|
+
created.uuid.should == b.uuid.gsub(/-/,'').upcase
|
|
47
|
+
created.minor.should == b.minor
|
|
48
|
+
created.major.should == b.major
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
it "should create a location with gps coordinates" do
|
|
52
|
+
gps = LocationGps.make
|
|
53
|
+
post "/api/v1/locations", { name: 'Test 123', kind: "airport", gps_attributes: gps.attributes }
|
|
54
|
+
response.should be_success
|
|
55
|
+
json['name'].should == "Test 123"
|
|
56
|
+
l = Location.find(json['id'])
|
|
57
|
+
created = l.gps
|
|
58
|
+
# Ruby and Postgres do not share the same floating point precision
|
|
59
|
+
created.lat.round(10).should == gps.lat.round(10)
|
|
60
|
+
created.lng.round(10).should == gps.lng.round(10)
|
|
61
|
+
created.alt.should == gps.alt
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
it "should validate a new location" do
|
|
65
|
+
post "/api/v1/locations", { name: 'test' }
|
|
66
|
+
response.code.should == "400"
|
|
67
|
+
json['error'].should == "Kind: is not included in the list"
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
it "should update the location" do
|
|
71
|
+
new_name = 'New Test 1234'
|
|
72
|
+
put "/api/v1/locations/#{location.id}", { name: new_name }
|
|
73
|
+
response.should be_success
|
|
74
|
+
location.reload
|
|
75
|
+
location.name.should == new_name
|
|
76
|
+
json['name'].should == new_name
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
it "should validate the location on update" do
|
|
80
|
+
old_kind = location.kind
|
|
81
|
+
put "/api/v1/locations/#{location.id}", { kind: 'bring the noise' }
|
|
82
|
+
response.code.should == "400"
|
|
83
|
+
location.reload
|
|
84
|
+
location.kind.should == old_kind
|
|
85
|
+
json['error'].should == 'Kind: is not included in the list'
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
it "should destroy the location and all of its child and grandchild locations" do
|
|
89
|
+
child_locations = location.child_locations.map {|l| [l.id, l.child_locations.map(&:id)] }.flatten
|
|
90
|
+
delete "/api/v1/locations/#{location.id}"
|
|
91
|
+
response.should be_success
|
|
92
|
+
Location.find_by_id(location.id).should == nil
|
|
93
|
+
Location.where(id: child_locations).size.should == 0
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
end
|