social_framework 0.0.3 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (30) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +34 -33
  3. data/app/helpers/social_framework/network_helper.rb +31 -14
  4. data/app/helpers/social_framework/route_helper.rb +81 -74
  5. data/app/helpers/social_framework/schedule_helper.rb +2 -1
  6. data/app/models/social_framework/event.rb +18 -14
  7. data/app/models/social_framework/user.rb +7 -3
  8. data/db/migrate/20160406165523_create_social_framework_participant_events.rb +2 -0
  9. data/db/migrate/20160516122239_create_social_framework_routes.rb +1 -0
  10. data/db/migrate/20160516122649_create_social_framework_locations.rb +2 -2
  11. data/db/tmp/migrate/20160406165523_create_social_framework_participant_events.rb +2 -0
  12. data/db/tmp/migrate/20160516122239_create_social_framework_routes.rb +1 -0
  13. data/db/tmp/migrate/20160516122649_create_social_framework_locations.rb +2 -2
  14. data/lib/generators/templates/initializers/social_framework.rb +0 -6
  15. data/lib/social_framework.rb +0 -8
  16. data/lib/social_framework/graphs/graph_elements.rb +3 -1
  17. data/lib/social_framework/version.rb +1 -1
  18. data/spec/controllers/social_framework/sessions_controller_spec.rb +10 -0
  19. data/spec/dummy/db/schema.rb +12 -10
  20. data/spec/dummy/log/development.log +871 -0
  21. data/spec/dummy/log/test.log +0 -0
  22. data/spec/dummy/social_framework_dev +0 -0
  23. data/spec/dummy/social_framework_test +0 -0
  24. data/spec/helpers/social_framework/route_helper_spec.rb +64 -35
  25. data/spec/models/social_framework/event_spec.rb +18 -4
  26. data/spec/models/social_framework/user_spec.rb +7 -0
  27. data/spec/spec_helper.rb +3 -0
  28. metadata +2 -5
  29. data/db/tmp/migrate/20160129004111_devise_create_social_framework_users.rb +0 -44
  30. data/spec/dummy/script.rb +0 -27
Binary file
@@ -151,19 +151,22 @@ module SocialFramework
151
151
 
152
152
  describe "Get near points" do
153
153
  it "When have near points" do
154
- result = @route_utils.send(:near_points, @route1, @route2, 1000)
154
+ @route2.accepted_deviation = 1000
155
+ result = @route_utils.send(:near_points, @route1, @route2)
155
156
  expect(result[:origins].count).to be(9)
156
157
  expect(result[:destinations].count).to be(7)
157
158
  end
158
159
 
159
160
  it "When dont have near points" do
160
- result = @route_utils.send(:near_points, @route1, @route2, 100)
161
+ @route2.accepted_deviation = 100
162
+ result = @route_utils.send(:near_points, @route1, @route2)
161
163
  expect(result[:origins]).to be_empty
162
164
  expect(result[:destinations]).to be_empty
163
165
  end
164
166
 
165
167
  it "When don't have near points in destinations" do
166
- result = @route_utils.send(:near_points, @route1, @route2, 300)
168
+ @route2.accepted_deviation = 300
169
+ result = @route_utils.send(:near_points, @route1, @route2)
167
170
  expect(result[:origins].count).to be(2)
168
171
  expect(result[:destinations]).to be_empty
169
172
  end
@@ -171,6 +174,7 @@ module SocialFramework
171
174
 
172
175
  describe "Compare routes" do
173
176
  it "When the principal accept both" do
177
+ @route1.accepted_deviation = 5000
174
178
  result = @route_utils.compare_routes(@route1, @route2)
175
179
 
176
180
  expect(result[:compatible]).to be(true)
@@ -181,9 +185,11 @@ module SocialFramework
181
185
  end
182
186
 
183
187
  it "When the principal accept any and secondary accept both" do
184
- principal = {mode: "driving", deviation: 4000}
185
- secondary = {mode: "walking", deviation: 1400}
186
- result = @route_utils.compare_routes(@route1, @route2, principal, secondary)
188
+ @route1.accepted_deviation = 4000
189
+ @route2.accepted_deviation = 1400
190
+ @route2.mode_of_travel = "walking"
191
+
192
+ result = @route_utils.compare_routes(@route1, @route2)
187
193
 
188
194
  expect(result[:compatible]).to be(true)
189
195
  expect(result[:principal_route][:deviation]).to be(:origin)
@@ -193,9 +199,11 @@ module SocialFramework
193
199
  end
194
200
 
195
201
  it "When the principal and secondary accept any" do
196
- principal = {mode: "driving", deviation: 4000}
197
- secondary = {mode: "walking", deviation: 650}
198
- result = @route_utils.compare_routes(@route1, @route2, principal, secondary)
202
+ @route1.accepted_deviation = 4000
203
+ @route2.accepted_deviation = 650
204
+ @route2.mode_of_travel = "walking"
205
+
206
+ result = @route_utils.compare_routes(@route1, @route2)
199
207
 
200
208
  expect(result[:compatible]).to be(true)
201
209
  expect(result[:principal_route][:deviation]).to be(:origin)
@@ -205,9 +213,11 @@ module SocialFramework
205
213
  end
206
214
 
207
215
  it "When the principal accept origin and secondary accept any" do
208
- principal = {mode: "driving", deviation: 2200}
209
- secondary = {mode: "walking", deviation: 650}
210
- result = @route_utils.compare_routes(@route1, @route3, principal, secondary)
216
+ @route1.accepted_deviation = 2200
217
+ @route3.accepted_deviation = 650
218
+ @route3.mode_of_travel = "walking"
219
+
220
+ result = @route_utils.compare_routes(@route1, @route3)
211
221
 
212
222
  expect(result[:compatible]).to be(true)
213
223
  expect(result[:principal_route][:deviation]).to be(:origin)
@@ -217,11 +227,12 @@ module SocialFramework
217
227
  end
218
228
 
219
229
  it "When the principal accept any and secondary accept origin" do
220
- principal = {mode: "driving", deviation: 3200}
221
- secondary = {mode: "walking", deviation: 500}
230
+ @route1.accepted_deviation = 3200
231
+ @route2.accepted_deviation = 500
232
+ @route2.mode_of_travel = "walking"
222
233
  @route2.locations.first.destroy
223
234
 
224
- result = @route_utils.compare_routes(@route1, @route2, principal, secondary)
235
+ result = @route_utils.compare_routes(@route1, @route2)
225
236
 
226
237
  expect(result[:compatible]).to be(true)
227
238
  expect(result[:principal_route][:deviation]).to be(:destiny)
@@ -231,10 +242,11 @@ module SocialFramework
231
242
  end
232
243
 
233
244
  it "When the principal accept any and secondary accept destiny" do
234
- principal = {mode: "driving", deviation: 4000}
235
- secondary = {mode: "walking", deviation: 630}
245
+ @route1.accepted_deviation = 4000
246
+ @route2.accepted_deviation = 630
247
+ @route2.mode_of_travel = "walking"
236
248
 
237
- result = @route_utils.compare_routes(@route1, @route2, principal, secondary)
249
+ result = @route_utils.compare_routes(@route1, @route2)
238
250
 
239
251
  expect(result[:compatible]).to be(true)
240
252
  expect(result[:principal_route][:deviation]).to be(:origin)
@@ -244,19 +256,21 @@ module SocialFramework
244
256
  end
245
257
 
246
258
  it "When the principal accept none and secondary accept destiny" do
247
- principal = {mode: "driving", deviation: 1000}
248
- secondary = {mode: "walking", deviation: 630}
259
+ @route1.accepted_deviation = 1000
260
+ @route2.accepted_deviation = 630
261
+ @route2.mode_of_travel = "walking"
249
262
 
250
- result = @route_utils.compare_routes(@route1, @route2, principal, secondary)
263
+ result = @route_utils.compare_routes(@route1, @route2)
251
264
 
252
265
  expect(result[:compatible]).to be(false)
253
266
  end
254
267
 
255
268
  it "When the principal accept any and secondary accept none" do
256
- principal = {mode: "driving", deviation: 3000}
257
- secondary = {mode: "walking", deviation: 500}
269
+ @route1.accepted_deviation = 3000
270
+ @route2.accepted_deviation = 500
271
+ @route2.mode_of_travel = "walking"
258
272
 
259
- result = @route_utils.compare_routes(@route1, @route2, principal, secondary)
273
+ result = @route_utils.compare_routes(@route1, @route2)
260
274
 
261
275
  expect(result[:compatible]).to be(false)
262
276
  end
@@ -264,55 +278,70 @@ module SocialFramework
264
278
 
265
279
  describe "Principal accept deviation" do
266
280
  it "When accept both" do
267
- result = @route_utils.send(:principal_accepted_deviation, @route1, @route2, 5000, "driving")
281
+ @route1.accepted_deviation = 5000
282
+ result = @route_utils.send(:principal_accepted_deviation, @route1, @route2)
268
283
  expect(result[:accept]).to be(:both)
269
284
  end
270
285
 
271
286
  it "When accept any" do
272
- result = @route_utils.send(:principal_accepted_deviation, @route1, @route2, 4000, "driving")
287
+ @route1.accepted_deviation = 4000
288
+ result = @route_utils.send(:principal_accepted_deviation, @route1, @route2)
273
289
  expect(result[:accept]).to be(:any)
274
290
  end
275
291
 
276
292
  it "When accept origin" do
277
- result = @route_utils.send(:principal_accepted_deviation, @route1, @route3, 2200, "driving")
293
+ @route1.accepted_deviation = 2200
294
+ result = @route_utils.send(:principal_accepted_deviation, @route1, @route3)
278
295
  expect(result[:accept]).to be(:origin)
279
296
  end
280
297
 
281
298
  it "When accept destiny" do
282
- result = @route_utils.send(:principal_accepted_deviation, @route1, @route2, 3000, "driving")
299
+ @route1.accepted_deviation = 3000
300
+ result = @route_utils.send(:principal_accepted_deviation, @route1, @route2)
283
301
  expect(result[:accept]).to be(:destiny)
284
302
  end
285
303
 
286
304
  it "When accept none" do
287
- result = @route_utils.send(:principal_accepted_deviation, @route1, @route2, 1000, "driving")
305
+ @route1.accepted_deviation = 1000
306
+ result = @route_utils.send(:principal_accepted_deviation, @route1, @route2)
288
307
  expect(result[:accept]).to be(:none)
289
308
  end
290
309
  end
291
310
 
292
311
  describe "Secondary accept deviation" do
293
312
  it "When accept both" do
294
- result = @route_utils.send(:secondary_accepted_deviation, @route1, @route2, 1400, "walking")
313
+ @route2.accepted_deviation = 1400
314
+ @route2.mode_of_travel = "walking"
315
+ result = @route_utils.send(:secondary_accepted_deviation, @route1, @route2)
295
316
  expect(result[:accept]).to be(:both)
296
317
  end
297
318
 
298
319
  it "When accept any" do
299
- result = @route_utils.send(:secondary_accepted_deviation, @route1, @route2, 650, "walking")
320
+ @route2.accepted_deviation = 650
321
+ @route2.mode_of_travel = "walking"
322
+ result = @route_utils.send(:secondary_accepted_deviation, @route1, @route2)
300
323
  expect(result[:accept]).to be(:any)
301
324
  end
302
325
 
303
326
  it "When accept origin" do
304
327
  @route2.locations.first.destroy
305
- result = @route_utils.send(:secondary_accepted_deviation, @route1, @route2, 500, "walking")
328
+ @route2.accepted_deviation = 500
329
+ @route2.mode_of_travel = "walking"
330
+ result = @route_utils.send(:secondary_accepted_deviation, @route1, @route2)
306
331
  expect(result[:accept]).to be(:origin)
307
332
  end
308
333
 
309
334
  it "When accept destiny" do
310
- result = @route_utils.send(:secondary_accepted_deviation, @route1, @route2, 630, "walking")
335
+ @route2.accepted_deviation = 630
336
+ @route2.mode_of_travel = "walking"
337
+ result = @route_utils.send(:secondary_accepted_deviation, @route1, @route2)
311
338
  expect(result[:accept]).to be(:destiny)
312
339
  end
313
340
 
314
341
  it "When accept none" do
315
- result = @route_utils.send(:secondary_accepted_deviation, @route1, @route2, 500, "walking")
342
+ @route2.accepted_deviation = 500
343
+ @route2.mode_of_travel = "walking"
344
+ result = @route_utils.send(:secondary_accepted_deviation, @route1, @route2)
316
345
  expect(result[:accept]).to be(:none)
317
346
  end
318
347
  end
@@ -328,7 +357,6 @@ module SocialFramework
328
357
 
329
358
  it "When origin points is empty" do
330
359
  result = @route_utils.send(:smallest_distance, [], @route2.locations.first, "walking")
331
- expect(result[:deviation]).to be_nil
332
360
  expect(result[:point]).to be_nil
333
361
  end
334
362
  end
@@ -339,6 +367,7 @@ module SocialFramework
339
367
  end
340
368
 
341
369
  it "When the principal accept both" do
370
+ @route1.accepted_deviation = 5000
342
371
  result = @context.compare_routes(@route1, @route2)
343
372
 
344
373
  expect(result[:compatible]).to be(true)
@@ -481,7 +481,7 @@ module SocialFramework
481
481
  end
482
482
  end
483
483
 
484
- describe "Get users confirmed" do
484
+ describe "Get users" do
485
485
  before(:each) do
486
486
  @user1.create_relationship @user2, "r1", true, true
487
487
  @user1.create_relationship @user3, "r1", true, true
@@ -491,16 +491,30 @@ module SocialFramework
491
491
  end
492
492
 
493
493
  it "When exist users not confirmed in event" do
494
- result = @event.send(:users)
494
+ result = @event.users
495
495
  expect(result.count).to be(1)
496
+
497
+ result = @event.users false
498
+ expect(result.count).to be(2)
496
499
  end
497
500
 
498
- it "When not exist users not confirmed in event" do
501
+ it "When all users confirmed in event" do
499
502
  @user2.schedule.confirm_event(@event)
500
503
  @user3.schedule.confirm_event(@event)
501
504
 
502
- result = @event.send(:users)
505
+ result = @event.users
503
506
  expect(result.count).to be(3)
507
+
508
+ result = @event.users false
509
+ expect(result).to be_empty
510
+ end
511
+
512
+ it "When get just creator" do
513
+ @user2.schedule.confirm_event(@event)
514
+ @user3.schedule.confirm_event(@event)
515
+
516
+ result = @event.users(true, "creator")
517
+ expect(result.count).to be(1)
504
518
  end
505
519
  end
506
520
 
@@ -287,6 +287,13 @@ module SocialFramework
287
287
 
288
288
  expect(result).not_to be_nil
289
289
  expect(result.locations.count).to be(4)
290
+ expect(@user.routes.first.accepted_deviation).to be(0)
291
+ expect(@user.routes.first.mode_of_travel).to eq("walking")
292
+ end
293
+
294
+ it "When pass a invalid mode_of_travel" do
295
+ result = @user.create_route("title1", 650, @locations, "invalid")
296
+ expect(result).to be_nil
290
297
  end
291
298
  end
292
299
  end
@@ -4,6 +4,9 @@ require "factory_girl"
4
4
  require "codeclimate-test-reporter"
5
5
  CodeClimate::TestReporter.start
6
6
 
7
+ require 'simplecov'
8
+ SimpleCov.start
9
+
7
10
  # This file was generated by the `rails generate rspec:install` command. Conventionally, all
8
11
  # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
9
12
  # The generated `.rspec` file contains `--require spec_helper` which will cause
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: social_framework
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jefferson Xavier
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-06-10 00:00:00.000000000 Z
12
+ date: 2016-06-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -82,7 +82,6 @@ files:
82
82
  - db/migrate/20160406165523_create_social_framework_participant_events.rb
83
83
  - db/migrate/20160516122239_create_social_framework_routes.rb
84
84
  - db/migrate/20160516122649_create_social_framework_locations.rb
85
- - db/tmp/migrate/20160129004111_devise_create_social_framework_users.rb
86
85
  - db/tmp/migrate/20160226123409_create_social_framework_edges.rb
87
86
  - db/tmp/migrate/20160406131316_create_social_framework_schedules.rb
88
87
  - db/tmp/migrate/20160406133419_create_social_framework_events.rb
@@ -158,7 +157,6 @@ files:
158
157
  - spec/dummy/public/422.html
159
158
  - spec/dummy/public/500.html
160
159
  - spec/dummy/public/favicon.ico
161
- - spec/dummy/script.rb
162
160
  - spec/dummy/social_framework_dev
163
161
  - spec/dummy/social_framework_test
164
162
  - spec/factories.rb
@@ -230,7 +228,6 @@ test_files:
230
228
  - spec/dummy/app/views/layouts/application.html.erb
231
229
  - spec/dummy/app/controllers/application_controller.rb
232
230
  - spec/dummy/Rakefile
233
- - spec/dummy/script.rb
234
231
  - spec/dummy/bin/setup
235
232
  - spec/dummy/bin/rails
236
233
  - spec/dummy/bin/bundle
@@ -1,44 +0,0 @@
1
- class DeviseCreateSocialFrameworkUsers < ActiveRecord::Migration
2
- def change
3
- create_table(:social_framework_users) do |t|
4
- ## Database authenticatable
5
- t.string :username, null: false
6
- t.string :email, null: false
7
- t.string :encrypted_password, null: false
8
-
9
- ## Recoverable
10
- t.string :reset_password_token
11
- t.datetime :reset_password_sent_at
12
-
13
- ## Rememberable
14
- t.datetime :remember_created_at
15
-
16
- ## Trackable
17
- t.integer :sign_in_count, default: 0, null: false
18
- t.datetime :current_sign_in_at
19
- t.datetime :last_sign_in_at
20
- t.string :current_sign_in_ip
21
- t.string :last_sign_in_ip
22
-
23
- ## Confirmable
24
- # t.string :confirmation_token
25
- # t.datetime :confirmed_at
26
- # t.datetime :confirmation_sent_at
27
- # t.string :unconfirmed_email # Only if using reconfirmable
28
-
29
- ## Lockable
30
- # t.integer :failed_attempts, default: 0, null: false # Only if lock strategy is :failed_attempts
31
- # t.string :unlock_token # Only if unlock strategy is :email or :both
32
- # t.datetime :locked_at
33
-
34
-
35
- t.timestamps null: false
36
- end
37
-
38
- add_index :social_framework_users, :email, unique: true
39
- add_index :social_framework_users, :username, unique: true
40
- add_index :social_framework_users, :reset_password_token, unique: true
41
- # add_index :social_framework_users, :confirmation_token, unique: true
42
- # add_index :social_framework_users, :unlock_token, unique: true
43
- end
44
- end
@@ -1,27 +0,0 @@
1
- # graph = SocialFramework::NetworkHelper::GraphStrategyDefault.get_instance 1
2
-
3
- # t1 = Time.now
4
- # u1 = SocialFramework::User.find 1
5
- # graph.build u1
6
- # t2 = Time.now
7
- # result = t2 - t1
8
- # puts "Tempo para montagem do grafo: #{result}"
9
-
10
- # f = Foo.new Set
11
-
12
- class Foo < ActiveRecord::Base
13
- has_one :bar
14
- end
15
-
16
- class Bar < ActiveRecord::Base
17
- belongs_to :foo
18
- def lala
19
- "LALA SUPERCLASSE"
20
- end
21
- end
22
-
23
- # class Bar2 < Bar
24
- # def lala
25
- # "LALA SUBCLASSE"
26
- # end
27
- # end