bigbluebutton_rails 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. data/.gitignore +2 -0
  2. data/.rvmrc +6 -0
  3. data/.travis.yml +4 -0
  4. data/CHANGELOG.rdoc +9 -0
  5. data/Gemfile +18 -0
  6. data/Gemfile.lock +85 -65
  7. data/README.rdoc +23 -0
  8. data/Rakefile +17 -6
  9. data/app/controllers/bigbluebutton/rooms_controller.rb +79 -58
  10. data/app/controllers/bigbluebutton/servers_controller.rb +41 -24
  11. data/app/models/bigbluebutton_room.rb +45 -5
  12. data/app/models/bigbluebutton_server.rb +5 -7
  13. data/app/views/bigbluebutton/rooms/external.html.erb +24 -0
  14. data/app/views/bigbluebutton/rooms/join_mobile.html.erb +1 -1
  15. data/app/views/bigbluebutton/servers/_activity_list.html.erb +7 -7
  16. data/app/views/bigbluebutton/servers/activity.html.erb +1 -1
  17. data/bigbluebutton_rails.gemspec +2 -12
  18. data/config/locales/en.yml +3 -0
  19. data/lib/bigbluebutton_rails/rails/routes.rb +12 -6
  20. data/lib/bigbluebutton_rails/utils.rb +8 -0
  21. data/lib/bigbluebutton_rails/version.rb +1 -1
  22. data/lib/bigbluebutton_rails.rb +1 -0
  23. data/spec/bigbluebutton_rails_spec.rb +13 -0
  24. data/spec/controllers/bigbluebutton/rooms_controller_exception_handling_spec.rb +114 -0
  25. data/spec/controllers/bigbluebutton/rooms_controller_json_responses_spec.rb +167 -0
  26. data/spec/controllers/bigbluebutton/rooms_controller_spec.rb +213 -457
  27. data/spec/controllers/bigbluebutton/servers_controller_json_responses_spec.rb +148 -0
  28. data/spec/controllers/bigbluebutton/servers_controller_spec.rb +50 -76
  29. data/spec/factories/bigbluebutton_room.rb +1 -0
  30. data/spec/models/bigbluebutton_room_spec.rb +141 -17
  31. data/spec/models/bigbluebutton_server_spec.rb +27 -36
  32. data/spec/rails_app/app/controllers/application_controller.rb +4 -3
  33. data/spec/rails_app/config/initializers/rack_hotfix.rb +13 -0
  34. data/spec/rails_app/features/join_external_bigbluebutton_rooms.feature +19 -0
  35. data/spec/rails_app/features/manage_bigbluebutton_rooms.feature +3 -3
  36. data/spec/rails_app/features/manage_bigbluebutton_servers.feature +2 -2
  37. data/spec/rails_app/features/step_definitions/bigbluebutton_room_steps.rb +29 -3
  38. data/spec/rails_app/features/step_definitions/bigbluebutton_server_steps.rb +2 -7
  39. data/spec/rails_app/features/step_definitions/common_steps.rb +15 -2
  40. data/spec/rails_app/features/step_definitions/web_steps.rb +7 -3
  41. data/spec/rails_app/features/support/application_controller.rb +12 -0
  42. data/spec/rails_app/features/support/content.rb +10 -0
  43. data/spec/rails_app/features/support/env.rb +4 -4
  44. data/spec/rails_app/features/support/env_gem.rb +2 -1
  45. data/spec/rails_app/features/support/forms.rb +12 -0
  46. data/spec/rails_app/features/support/paths.rb +17 -8
  47. data/spec/rails_app/features/support/selectors.rb +57 -0
  48. data/spec/rails_app/features/support/within.rb +7 -0
  49. data/spec/routing/bigbluebutton/rooms_routing_spec.rb +60 -52
  50. data/spec/routing/bigbluebutton/servers_routing_spec.rb +8 -8
  51. data/spec/spec_helper.rb +5 -0
  52. data/spec/support/controllers/bigbluebutton/rooms_controller.rb +7 -0
  53. data/spec/support/matchers/shoulda/be_boolean.rb +1 -1
  54. data/spec/support/shared_examples/rooms_controller.rb +37 -0
  55. metadata +24 -110
  56. data/spec/rails_app/app/helpers/application_helper.rb +0 -2
@@ -1,17 +1,10 @@
1
1
  require 'spec_helper'
2
- require 'bigbluebutton-api'
2
+ require 'bigbluebutton_api'
3
3
 
4
4
  # Some tests mock the server and its API object
5
5
  # We don't want to trigger real API calls here (this is done in the integration tests)
6
6
 
7
- def build_running_json(value, error=nil)
8
- hash = { :running => "#{value}" }
9
- hash[:error] = error unless error.nil?
10
- hash.to_json
11
- end
12
-
13
7
  describe Bigbluebutton::RoomsController do
14
-
15
8
  render_views
16
9
  let(:server) { Factory.create(:bigbluebutton_server) }
17
10
  let(:room) { Factory.create(:bigbluebutton_room, :server => server) }
@@ -50,19 +43,25 @@ describe Bigbluebutton::RoomsController do
50
43
 
51
44
  describe "#join_mobile" do
52
45
  let(:user) { Factory.build(:user) }
46
+ let(:server) { Factory.create(:bigbluebutton_server) }
47
+ let(:room) { Factory.create(:bigbluebutton_room, :server => server) }
53
48
  before {
54
49
  mock_server_and_api
55
50
  controller.stub(:bigbluebutton_user) { user }
56
51
  controller.should_receive(:bigbluebutton_role).and_return(:moderator)
52
+ controller.should_receive(:join_bigbluebutton_server_room_path).
53
+ with(mocked_server, room, :mobile => '1').
54
+ and_return("http://test.com/join/url?mobile=1")
57
55
  mocked_api.should_receive(:join_meeting_url).
58
56
  with(room.meetingid, user.name, room.moderator_password).
59
- and_return("http://join_url")
57
+ and_return("bigbluebutton://test.com/open/url/for/qrcode")
60
58
  }
61
59
  before(:each) { get :join_mobile, :server_id => mocked_server.to_param, :id => room.to_param }
62
60
  it { should respond_with(:success) }
63
61
  it { should assign_to(:server).with(mocked_server) }
64
62
  it { should assign_to(:room).with(room) }
65
- it { should assign_to(:join_url).with("bigbluebutton://join_url") }
63
+ it { should assign_to(:join_url).with("bigbluebutton://test.com/join/url?mobile=1") }
64
+ it { should assign_to(:qrcode_url).with("bigbluebutton://test.com/open/url/for/qrcode") }
66
65
  it { should render_template(:join_mobile) }
67
66
  end
68
67
 
@@ -283,124 +282,26 @@ describe Bigbluebutton::RoomsController do
283
282
  end
284
283
  end
285
284
 
286
- context do
287
- before { controller.stub(:bigbluebutton_user) { user } }
288
-
289
- context "if the user is a moderator" do
290
- before {
291
- controller.should_receive(:bigbluebutton_role).with(room).and_return(:moderator)
292
- mocked_api.should_receive(:join_meeting_url).with(room.meetingid, user.name, room.moderator_password).
293
- and_return("http://test.com/mod/join")
294
- }
295
-
296
- context "and the conference is running" do
297
- before {
298
- mocked_api.should_receive(:is_meeting_running?).and_return(true)
299
- }
300
-
301
- it "assigns server" do
302
- get :join, :server_id => mocked_server.to_param, :id => room.to_param
303
- should assign_to(:server).with(mocked_server)
304
- end
305
-
306
- it "redirects to the moderator join url" do
307
- get :join, :server_id => mocked_server.to_param, :id => room.to_param
308
- should respond_with(:redirect)
309
- should redirect_to("http://test.com/mod/join")
310
- end
311
- end
312
-
313
- context "and the conference is NOT running" do
314
- before {
315
- mocked_api.should_receive(:is_meeting_running?).and_return(false)
316
- }
317
-
318
- it "creates the conference" do
319
- mocked_api.should_receive(:create_meeting).
320
- with(room.name, room.meetingid, room.moderator_password,
321
- room.attendee_password, room.welcome_msg, room.dial_number,
322
- room.logout_url, room.max_participants, room.voice_bridge)
323
- get :join, :server_id => mocked_server.to_param, :id => room.to_param
324
- end
325
-
326
- context "adds the protocol/domain to logout_url" do
327
- after :each do
328
- get :join, :server_id => mocked_server.to_param, :id => room.to_param
329
- end
330
-
331
- it "when it doesn't have protocol neither domain" do
332
- room.update_attributes(:logout_url => "/incomplete/url")
333
- full_logout_url = "http://test.host" + room.logout_url
334
-
335
- mocked_api.should_receive(:create_meeting).
336
- with(anything, anything, anything, anything, anything, anything,
337
- full_logout_url, anything, anything)
338
- end
339
-
340
- it "when it doesn't have protocol only" do
341
- room.update_attributes(:logout_url => "www.host.com/incomplete/url")
342
- full_logout_url = "http://" + room.logout_url
343
-
344
- mocked_api.should_receive(:create_meeting).
345
- with(anything, anything, anything, anything, anything, anything,
346
- full_logout_url, anything, anything)
347
- end
348
-
349
- it "but not when it has a protocol defined" do
350
- room.update_attributes(:logout_url => "http://with/protocol")
351
- mocked_api.should_receive(:create_meeting).
352
- with(anything, anything, anything, anything, anything, anything,
353
- room.logout_url, anything, anything)
354
- end
355
- end
356
-
357
- end
358
-
359
- end
360
-
361
- context "if the user is an attendee" do
362
- before {
363
- controller.should_receive(:bigbluebutton_role).with(room).and_return(:attendee)
364
- }
365
-
366
- context "and the conference is running" do
367
- before {
368
- mocked_api.should_receive(:is_meeting_running?).and_return(true)
369
- mocked_api.should_receive(:join_meeting_url).with(room.meetingid, user.name, room.attendee_password).
370
- and_return("http://test.com/attendee/join")
371
- }
372
-
373
- it "assigns server" do
374
- get :join, :server_id => mocked_server.to_param, :id => room.to_param
375
- should assign_to(:server).with(mocked_server)
376
- end
377
-
378
- it "redirects to the attendee join url" do
379
- get :join, :server_id => mocked_server.to_param, :id => room.to_param
380
- should respond_with(:redirect)
381
- should redirect_to("http://test.com/attendee/join")
382
- end
383
- end
384
-
385
- context "and the conference is NOT running" do
386
- before {
387
- mocked_api.should_receive(:is_meeting_running?).and_return(false)
388
- }
389
-
390
- it "do not try to create the conference" do
391
- mocked_api.should_not_receive(:create_meeting)
392
- get :join, :server_id => mocked_server.to_param, :id => room.to_param
393
- end
394
-
395
- it "renders #join to wait for a moderator" do
396
- get :join, :server_id => mocked_server.to_param, :id => room.to_param
397
- should respond_with(:success)
398
- should render_template(:join)
399
- end
400
- end
401
-
402
- end
285
+ # verify the behaviour of .join_internal
286
+ # see support/shared_examples/rooms_controller.rb
287
+ context "calling .join_internal" do
288
+ let(:template) { :join }
289
+ let(:request) { get :join, :server_id => mocked_server.to_param, :id => room.to_param }
290
+ before { controller.stub(:bigbluebutton_user).and_return(user) }
291
+ it_should_behave_like "internal join caller"
292
+ end
403
293
 
294
+ context "when :mobile => true" do
295
+ before {
296
+ controller.stub(:bigbluebutton_user) { user }
297
+ controller.stub(:bigbluebutton_role) { :moderator }
298
+ BigbluebuttonRoom.stub(:find_by_param).and_return(room)
299
+ room.should_receive(:perform_join).and_return("http://test.com/join/url")
300
+ }
301
+ before(:each) {
302
+ get :join, :server_id => mocked_server.to_param, :id => room.to_param, :mobile => "1"
303
+ }
304
+ it { should redirect_to("bigbluebutton://test.com/join/url") }
404
305
  end
405
306
 
406
307
  end
@@ -503,6 +404,30 @@ describe Bigbluebutton::RoomsController do
503
404
  controller.stub(:bigbluebutton_user).and_return(nil)
504
405
  }
505
406
 
407
+ context "assigns @room" do
408
+ let(:user_hash) { { :name => "Elftor", :password => room.attendee_password } }
409
+ let(:meetingid) { "my-meeting-id" }
410
+ let(:http_referer) { bigbluebutton_server_path(mocked_server) }
411
+ before {
412
+ mocked_api.stub!(:is_meeting_running?)
413
+ request.env["HTTP_REFERER"] = http_referer
414
+ }
415
+
416
+ context "if params[:id]" do
417
+ before(:each) { post :auth, :server_id => mocked_server.to_param, :id => room.to_param, :user => user_hash }
418
+ it { should assign_to(:room).with(room) }
419
+ end
420
+
421
+ context "if params[:id] doesn't exists" do
422
+ let(:message) { I18n.t('bigbluebutton_rails.rooms.errors.auth.wrong_params') }
423
+ before(:each) { post :auth, :server_id => mocked_server.to_param, :id => "inexistent-room-id", :user => user_hash }
424
+ it { should assign_to(:room).with(nil) }
425
+ it { should respond_with(:redirect) }
426
+ it { should redirect_to(http_referer) }
427
+ it { should set_the_flash.to(message) }
428
+ end
429
+ end
430
+
506
431
  context "block access if bigbluebutton_role returns nil" do
507
432
  let(:hash) { { :name => "Elftor", :password => room.attendee_password } }
508
433
  before { controller.stub(:bigbluebutton_role) { nil } }
@@ -513,402 +438,233 @@ describe Bigbluebutton::RoomsController do
513
438
  }
514
439
  end
515
440
 
516
- context "if there's a user logged, should use it's name" do
517
- let(:hash) { { :name => "Elftor", :password => room.attendee_password } }
518
- it do
519
- controller.stub(:bigbluebutton_user).and_return(user)
520
- mocked_api.should_receive(:is_meeting_running?).and_return(true)
521
- mocked_api.should_receive(:join_meeting_url).
522
- with(room.meetingid, user.name, room.attendee_password).
523
- and_return("http://test.com/attendee/join")
524
- post :auth, :server_id => mocked_server.to_param, :id => room.to_param, :user => hash
525
- should respond_with(:redirect)
526
- should redirect_to("http://test.com/attendee/join")
527
- end
441
+ it "if there's a user logged, should use his name" do
442
+ controller.stub(:bigbluebutton_role) { :password }
443
+ hash = { :name => "Elftor", :password => room.attendee_password }
444
+ controller.stub(:bigbluebutton_user).and_return(user)
445
+ mocked_api.should_receive(:is_meeting_running?).and_return(true)
446
+ mocked_api.should_receive(:join_meeting_url).
447
+ with(room.meetingid, user.name, room.attendee_password). # here's the validation
448
+ and_return("http://test.com/attendee/join")
449
+ post :auth, :server_id => mocked_server.to_param, :id => room.to_param, :user => hash
528
450
  end
529
451
 
530
- context "shows error when" do
452
+ it "redirects to the correct join_url" do
453
+ hash = { :name => "Elftor", :password => room.attendee_password }
454
+ mocked_api.should_receive(:is_meeting_running?).and_return(true)
455
+ mocked_api.should_receive(:join_meeting_url).and_return("http://test.com/attendee/join")
456
+ post :auth, :server_id => mocked_server.to_param, :id => room.to_param, :user => hash
457
+ should respond_with(:redirect)
458
+ should redirect_to("http://test.com/attendee/join")
459
+ end
531
460
 
532
- context "name is not set" do
533
- let(:hash) { { :password => room.moderator_password } }
534
- before(:each) { post :auth, :server_id => mocked_server.to_param, :id => room.to_param, :user => hash }
461
+ it "use bigbluebutton_role when the return is diferent of password" do
462
+ controller.stub(:bigbluebutton_role) { :attendee }
463
+ hash = { :name => "Elftor", :password => nil }
464
+ mocked_api.should_receive(:is_meeting_running?).and_return(true)
465
+ mocked_api.should_receive(:join_meeting_url).
466
+ with(anything, anything, room.attendee_password).
467
+ and_return("http://test.com/attendee/join")
468
+ post :auth, :server_id => mocked_server.to_param, :id => room.to_param, :user => hash
469
+ should respond_with(:redirect)
470
+ should redirect_to("http://test.com/attendee/join")
471
+ end
472
+
473
+ context "validates user input and shows error" do
474
+ before { controller.should_receive(:bigbluebutton_role).once { :password } }
475
+ before(:each) { post :auth, :server_id => mocked_server.to_param, :id => room.to_param, :user => user_hash }
476
+
477
+ context "when name is not set" do
478
+ let(:user_hash) { { :password => room.moderator_password } }
535
479
  it { should respond_with(:unauthorized) }
536
480
  it { should assign_to(:room).with(room) }
537
481
  it { should render_template(:invite) }
538
482
  it { should set_the_flash.to(I18n.t('bigbluebutton_rails.rooms.errors.auth.failure')) }
539
483
  end
540
484
 
541
- context "the password is wrong" do
542
- let(:hash) { { :name => "Elftor", :password => nil } }
543
- before(:each) { post :auth, :server_id => mocked_server.to_param, :id => room.to_param, :user => hash }
485
+ context "when the password is wrong" do
486
+ let(:user_hash) { { :name => "Elftor", :password => nil } }
544
487
  it { should respond_with(:unauthorized) }
545
488
  it { should assign_to(:room).with(room) }
546
489
  it { should render_template(:invite) }
547
490
  it { should set_the_flash.to(I18n.t('bigbluebutton_rails.rooms.errors.auth.failure')) }
548
491
  end
549
-
550
492
  end
551
493
 
552
- context "entering the attendee password" do
553
- let(:hash) { { :name => "Elftor", :password => room.attendee_password } }
554
-
555
- # OPTMIZE Almost the same tests as in #join. Can they be integrated somehow?
556
- context "and the conference is running" do
557
- before {
558
- mocked_api.should_receive(:is_meeting_running?).and_return(true)
559
- mocked_api.should_receive(:join_meeting_url).and_return("http://test.com/attendee/join")
560
- }
561
-
562
- it "assigns server" do
563
- post :auth, :server_id => mocked_server.to_param, :id => room.to_param, :user => hash
564
- should assign_to(:server).with(mocked_server)
565
- end
566
-
567
- it "redirects to the attendee join url" do
568
- post :auth, :server_id => mocked_server.to_param, :id => room.to_param, :user => hash
569
- should respond_with(:redirect)
570
- should redirect_to("http://test.com/attendee/join")
571
- end
572
- end
573
-
574
- context "and the conference is NOT running" do
575
- before {
576
- mocked_api.should_receive(:is_meeting_running?).and_return(false)
577
- }
578
-
579
- it "do not try to create the conference" do
580
- mocked_api.should_not_receive(:create_meeting)
581
- post :auth, :server_id => mocked_server.to_param, :id => room.to_param, :user => hash
582
- end
583
-
584
- it "renders #invite" do
585
- post :auth, :server_id => mocked_server.to_param, :id => room.to_param, :user => hash
586
- should respond_with(:success)
587
- should render_template(:invite)
588
- should set_the_flash.to(I18n.t('bigbluebutton_rails.rooms.errors.auth.not_running'))
589
- end
590
- end
591
-
494
+ # verify the behaviour of .join_internal
495
+ # see support/shared_examples/rooms_controller.rb
496
+ context "calling .join_internal" do
497
+ let(:template) { :invite }
498
+ let(:hash) { { :name => user.name, :password => room.attendee_password } }
499
+ let(:request) { post :auth, :server_id => mocked_server.to_param, :id => room.to_param, :user => hash }
500
+ before { controller.stub(:bigbluebutton_user).and_return(nil) }
501
+ it_should_behave_like "internal join caller"
592
502
  end
503
+ end
593
504
 
594
- context "entering the moderator password" do
595
- let(:hash) { { :name => "Elftor", :password => room.moderator_password } }
596
-
597
- # OPTMIZE Almost the same tests as in #join. Can they be integrated somehow?
598
- before {
599
- mocked_api.should_receive(:join_meeting_url).and_return("http://test.com/mod/join")
600
- }
505
+ describe "#external" do
506
+ before { mock_server_and_api }
507
+ let(:new_room) { BigbluebuttonRoom.new(:meetingid => 'my-meeting-id') }
601
508
 
602
- context "and the conference is running" do
603
- before {
604
- mocked_api.should_receive(:is_meeting_running?).and_return(true)
605
- }
509
+ context "on success" do
510
+ before { controller.stub(:bigbluebutton_user).and_return(nil) }
511
+ before(:each) { get :external, :server_id => mocked_server.to_param, :meeting => new_room.meetingid }
512
+ it { should assign_to(:server).with(mocked_server) }
513
+ it { should respond_with(:success) }
514
+ it { should render_template(:external) }
515
+ it { should assign_to(:room).with_kind_of(BigbluebuttonRoom) }
516
+ it { assigns(:room).meetingid.should be(new_room.meetingid) }
517
+ end
606
518
 
607
- it "assigns server" do
608
- post :auth, :server_id => mocked_server.to_param, :id => room.to_param, :user => hash
609
- should assign_to(:server).with(mocked_server)
610
- end
519
+ context "when params[:meeting].blank?" do
520
+ before { controller.stub(:bigbluebutton_user).and_return(nil) }
611
521
 
612
- it "redirects to the moderator join url" do
613
- post :auth, :server_id => mocked_server.to_param, :id => room.to_param, :user => hash
614
- should respond_with(:redirect)
615
- should redirect_to("http://test.com/mod/join")
616
- end
522
+ context "without params[:redir_url]" do
523
+ before(:each) { get :external, :server_id => mocked_server.to_param }
524
+ it { should respond_with(:redirect) }
525
+ it { should redirect_to bigbluebutton_server_rooms_path(mocked_server) }
526
+ it { should set_the_flash.to(I18n.t('bigbluebutton_rails.rooms.errors.external.blank_meetingid')) }
617
527
  end
618
528
 
619
- context "and the conference is NOT running" do
620
- before {
621
- mocked_api.should_receive(:is_meeting_running?).and_return(false)
622
- }
623
-
624
- it "creates the conference" do
625
- mocked_api.should_receive(:create_meeting).
626
- with(room.name, room.meetingid, room.moderator_password,
627
- room.attendee_password, room.welcome_msg, room.dial_number,
628
- room.logout_url, room.max_participants, room.voice_bridge)
629
- post :auth, :server_id => mocked_server.to_param, :id => room.to_param, :user => hash
630
- end
529
+ context "with params[:redir_url]" do
530
+ before(:each) { get :external, :server_id => mocked_server.to_param, :redir_url => '/'}
531
+ it { should redirect_to '/' }
631
532
  end
632
-
633
533
  end
634
- end
635
-
636
- # can be used when matching rooms inside some resource other than servers
637
- context "selects the first server when the server_id in the url is inexistent" do
638
- let(:server2) { Factory.create(:bigbluebutton_server) }
639
-
640
- # get /users/:user_id/room/:id(.:format)
641
- before(:each) { get :show, :id => room.to_param, :user_id => "1" }
642
- it { should respond_with(:success) }
643
- it { should assign_to(:server).with(server) }
644
- end
534
+ end # #external
645
535
 
646
- # make sure that the exceptions thrown by bigbluebutton-api-ruby are treated by the controller
647
- context "exception handling" do
648
- let(:bbb_error_msg) { "err msg" }
649
- let(:bbb_error) { BigBlueButton::BigBlueButtonException.new(bbb_error_msg) }
536
+ describe "#external_auth" do
537
+ let(:user) { Factory.build(:user) }
538
+ let(:user_hash) { { :name => "Elftor", :password => new_room.attendee_password } }
539
+ let(:meetingid) { "my-meeting-id" }
540
+ let(:new_room) { BigbluebuttonRoom.new(:meetingid => meetingid,
541
+ :attendee_password => Forgery(:basic).password,
542
+ :moderator_password => Forgery(:basic).password,
543
+ :server => mocked_server) }
544
+ let(:meetings) { [ new_room ] }
650
545
  let(:http_referer) { bigbluebutton_server_path(mocked_server) }
651
546
  before {
652
547
  mock_server_and_api
548
+ controller.stub(:bigbluebutton_user).and_return(nil)
653
549
  request.env["HTTP_REFERER"] = http_referer
654
550
  }
655
551
 
656
- describe "#destroy" do
657
- it "catches exception on is_meeting_running" do
658
- mocked_api.should_receive(:is_meeting_running?) { raise bbb_error }
552
+ context "assigns @room" do
553
+ context "if params[:meeting] and params[:user]" do
554
+ before { # TODO: this block is being repeated several times, put it in a method or something
555
+ mocked_server.should_receive(:fetch_meetings)
556
+ mocked_server.should_receive(:meetings).and_return(meetings)
557
+ new_room.should_receive(:fetch_meeting_info)
558
+ }
559
+ before(:each) { post :external_auth, :server_id => mocked_server.to_param, :meeting => new_room.meetingid, :user => user_hash }
560
+ it { should assign_to(:room).with(new_room) }
659
561
  end
660
562
 
661
- it "catches exception on end_meeting" do
662
- mocked_api.should_receive(:is_meeting_running?).and_return(true)
663
- mocked_api.should_receive(:end_meeting) { raise bbb_error }
563
+ context "if not params[:meeting]" do
564
+ let(:message) { I18n.t('bigbluebutton_rails.rooms.errors.auth.wrong_params') }
565
+ before(:each) { post :external_auth, :server_id => mocked_server.to_param, :meeting => nil, :user => user_hash }
566
+ it { should assign_to(:room).with(nil) }
567
+ it { should respond_with(:redirect) }
568
+ it { should redirect_to(http_referer) }
569
+ it { should set_the_flash.to(message) }
664
570
  end
665
571
 
666
- after :each do
667
- delete :destroy, :server_id => mocked_server.to_param, :id => room.to_param
668
- should respond_with(:redirect)
669
- should redirect_to bigbluebutton_server_rooms_url
670
- should set_the_flash.to(bbb_error_msg)
572
+ context "if not params[:user]" do
573
+ let(:message) { I18n.t('bigbluebutton_rails.rooms.errors.auth.wrong_params') }
574
+ before(:each) { post :external_auth, :server_id => mocked_server.to_param, :meeting => new_room.meetingid, :user => nil }
575
+ it { should assign_to(:room).with(nil) }
576
+ it { should respond_with(:redirect) }
577
+ it { should redirect_to(http_referer) }
578
+ it { should set_the_flash.to(message) }
671
579
  end
672
580
  end
673
581
 
674
- describe "#running" do
675
- before { mocked_api.should_receive(:is_meeting_running?) { raise bbb_error } }
676
- before(:each) { get :running, :server_id => mocked_server.to_param, :id => room.to_param }
677
- it { should respond_with(:success) }
678
- it { response.body.should == build_running_json(false, bbb_error_msg) }
679
- it { should set_the_flash.to(bbb_error_msg) }
680
- end
681
-
682
- describe "#end" do
683
- it "catches exception on is_meeting_running" do
684
- mocked_api.should_receive(:is_meeting_running?) { raise bbb_error }
685
- end
582
+ context "got the room" do
583
+ before {
584
+ mocked_server.should_receive(:fetch_meetings)
585
+ mocked_server.should_receive(:meetings).and_return(meetings)
586
+ }
686
587
 
687
- it "catches exception on end_meeting" do
688
- mocked_api.should_receive(:is_meeting_running?).and_return(true)
689
- mocked_api.should_receive(:end_meeting) { raise bbb_error }
588
+ it "block access if bigbluebutton_role returns nil" do
589
+ controller.stub(:bigbluebutton_role) { nil }
590
+ lambda {
591
+ post :external_auth, :server_id => mocked_server.to_param, :meeting => new_room.meetingid, :user => user_hash
592
+ }.should raise_error(BigbluebuttonRails::RoomAccessDenied)
690
593
  end
691
594
 
692
- after :each do
693
- get :end, :server_id => mocked_server.to_param, :id => room.to_param
694
- should respond_with(:redirect)
695
- should redirect_to(http_referer)
696
- should set_the_flash.to(bbb_error_msg)
595
+ it "fetches meeting info" do
596
+ new_room.should_receive(:fetch_meeting_info)
597
+ post :external_auth, :server_id => mocked_server.to_param, :meeting => new_room.meetingid, :user => user_hash
697
598
  end
698
- end
699
599
 
700
- describe "#join" do
701
- before { controller.stub(:bigbluebutton_user) { Factory.build(:user) } }
600
+ context "validates user input and shows error" do
601
+ before(:each) { post :external_auth, :server_id => mocked_server.to_param, :meeting => new_room.meetingid, :user => user_hash }
702
602
 
703
- context "as moderator" do
704
- before { controller.should_receive(:bigbluebutton_role).with(room).and_return(:moderator) }
705
-
706
- it "catches exception on is_meeting_running" do
707
- mocked_api.should_receive(:is_meeting_running?) { raise bbb_error }
603
+ context "when name is not set" do
604
+ let(:user_hash) { { :password => room.moderator_password } }
605
+ it { should respond_with(:unauthorized) }
606
+ it { should assign_to(:room).with(new_room) }
607
+ it { should render_template(:external) }
608
+ it { should set_the_flash.to(I18n.t('bigbluebutton_rails.rooms.errors.auth.failure')) }
708
609
  end
709
610
 
710
- it "catches exception on create_meeting" do
711
- mocked_api.should_receive(:is_meeting_running?).and_return(false)
712
- mocked_api.should_receive(:create_meeting) { raise bbb_error }
611
+ context "when the password is wrong" do
612
+ let(:user_hash) { { :name => "Elftor", :password => nil } }
613
+ it { should respond_with(:unauthorized) }
614
+ it { should assign_to(:room).with(new_room) }
615
+ it { should render_template(:external) }
616
+ it { should set_the_flash.to(I18n.t('bigbluebutton_rails.rooms.errors.auth.failure')) }
713
617
  end
714
-
715
- it "catches exception on join_meeting_url" do
716
- mocked_api.should_receive(:is_meeting_running?).and_return(true)
717
- mocked_api.should_receive(:join_meeting_url) { raise bbb_error }
718
- end
719
-
720
- after :each do
721
- get :join, :server_id => mocked_server.to_param, :id => room.to_param
722
- should respond_with(:redirect)
723
- should redirect_to(http_referer)
724
- should set_the_flash.to(bbb_error_msg)
725
- end
726
-
727
618
  end
728
619
 
729
- context "as moderator" do
730
- before { controller.should_receive(:bigbluebutton_role).with(room).and_return(:attendee) }
731
-
732
- it "catches exception on is_meeting_running" do
733
- mocked_api.should_receive(:is_meeting_running?) { raise bbb_error }
734
- end
620
+ context "and the meeting is running" do
621
+ before {
622
+ new_room.should_receive(:fetch_meeting_info)
623
+ new_room.running = true
624
+ }
735
625
 
736
- it "catches exception on join_meeting_url" do
737
- mocked_api.should_receive(:is_meeting_running?).and_return(true)
738
- mocked_api.should_receive(:join_meeting_url) { raise bbb_error }
626
+ it "if there's a user logged, should use his name" do
627
+ controller.stub(:bigbluebutton_user).and_return(user)
628
+ mocked_api.should_receive(:join_meeting_url).
629
+ with(new_room.meetingid, user.name, new_room.attendee_password). # here's the validation
630
+ and_return("http://test.com/attendee/join")
631
+ post :external_auth, :server_id => mocked_server.to_param, :meeting => new_room.meetingid, :user => user_hash
739
632
  end
740
633
 
741
- after :each do
742
- get :join, :server_id => mocked_server.to_param, :id => room.to_param
634
+ it "redirects to the correct join_url" do
635
+ controller.stub(:bigbluebutton_user).and_return(user)
636
+ mocked_api.should_receive(:join_meeting_url).
637
+ and_return("http://test.com/attendee/join")
638
+ post :external_auth, :server_id => mocked_server.to_param, :meeting => new_room.meetingid, :user => user_hash
743
639
  should respond_with(:redirect)
744
- should redirect_to(http_referer)
745
- should set_the_flash.to(bbb_error_msg)
640
+ should redirect_to("http://test.com/attendee/join")
746
641
  end
747
642
  end
748
643
 
749
- end # #join
750
-
751
- end # exception handling
752
-
753
- # verify all JSON responses
754
- context "json responses for " do
755
- describe "#index" do
756
- before do
757
- @room1 = Factory.create(:bigbluebutton_room, :server => server)
758
- @room2 = Factory.create(:bigbluebutton_room, :server => server)
759
- end
760
- before(:each) { get :index, :server_id => server.to_param, :format => 'json' }
761
- it { should respond_with(:success) }
762
- it { should respond_with_content_type(:json) }
763
- it { should respond_with_json([@room1, @room2].to_json) }
764
- end
765
-
766
- describe "#new" do
767
- before(:each) { get :new, :server_id => server.to_param, :format => 'json' }
768
- it { should respond_with(:success) }
769
- it { should respond_with_content_type(:json) }
770
- it {
771
- # we ignore all values bc a BigbluebuttonRoom is generated with some
772
- # random values (meetingid, voice_bridge)
773
- should respond_with_json(BigbluebuttonRoom.new.to_json).ignoring_values
774
- }
775
- end
776
-
777
- describe "#show" do
778
- before(:each) { get :show, :server_id => server.to_param, :id => room.to_param, :format => 'json' }
779
- it { should respond_with(:success) }
780
- it { should respond_with_content_type(:json) }
781
- it { should respond_with_json(room.to_json) }
782
- end
783
-
784
- describe "#create" do
785
- let(:new_room) { Factory.build(:bigbluebutton_room, :server => server) }
786
-
787
- context "on success" do
788
- before(:each) {
789
- post :create, :server_id => server.to_param, :bigbluebutton_room => new_room.attributes, :format => 'json'
790
- }
791
- it { should respond_with(:created) }
792
- it { should respond_with_content_type(:json) }
793
- it {
794
- json = { :message => I18n.t('bigbluebutton_rails.rooms.notice.create.success') }.to_json
795
- should respond_with_json(json)
796
- }
797
- end
798
-
799
- context "on failure" do
800
- before(:each) {
801
- new_room.name = nil # invalid
802
- post :create, :server_id => server.to_param, :bigbluebutton_room => new_room.attributes, :format => 'json'
803
- }
804
- it { should respond_with(:unprocessable_entity) }
805
- it { should respond_with_content_type(:json) }
806
- it {
807
- new_room.save # should fail
808
- should respond_with_json(new_room.errors.full_messages.to_json)
809
- }
810
- end
811
- end
812
-
813
- describe "#update" do
814
- let(:new_room) { Factory.build(:bigbluebutton_room) }
815
- before { @room = room }
816
-
817
- context "on success" do
818
- before(:each) {
819
- put :update, :server_id => server.to_param, :id => @room.to_param, :bigbluebutton_room => new_room.attributes, :format => 'json'
820
- }
821
- it { should respond_with(:success) }
822
- it { should respond_with_content_type(:json) }
823
- it {
824
- json = { :message => I18n.t('bigbluebutton_rails.rooms.notice.update.success') }.to_json
825
- should respond_with_json(json)
826
- }
827
- end
828
-
829
- context "on failure" do
830
- before(:each) {
831
- new_room.name = nil # invalid
832
- put :update, :server_id => server.to_param, :id => @room.to_param, :bigbluebutton_room => new_room.attributes, :format => 'json'
833
- }
834
- it { should respond_with(:unprocessable_entity) }
835
- it { should respond_with_content_type(:json) }
836
- it {
837
- new_room.save # should fail
838
- should respond_with_json(new_room.errors.full_messages.to_json)
839
- }
840
- end
841
- end
842
-
843
- describe "#end" do
844
- before { mock_server_and_api }
845
-
846
- context "room is running" do
644
+ context "and the meeting is not running" do
847
645
  before {
848
- mocked_api.should_receive(:is_meeting_running?).and_return(true)
849
- mocked_api.should_receive(:end_meeting).with(room.meetingid, room.moderator_password)
646
+ new_room.should_receive(:fetch_meeting_info)
647
+ new_room.running = false
850
648
  }
851
- before(:each) { get :end, :server_id => mocked_server.to_param, :id => room.to_param, :format => 'json' }
649
+ before(:each) { post :external_auth, :server_id => mocked_server.to_param, :meeting => new_room.meetingid, :user => user_hash }
852
650
  it { should respond_with(:success) }
853
- it { should respond_with_content_type(:json) }
854
- it { should respond_with_json(I18n.t('bigbluebutton_rails.rooms.notice.end.success')) }
855
- end
856
-
857
- context "room is not running" do
858
- before { mocked_api.should_receive(:is_meeting_running?).and_return(false) }
859
- before(:each) { get :end, :server_id => mocked_server.to_param, :id => room.to_param, :format => 'json' }
860
- it { should respond_with(:error) }
861
- it { should respond_with_content_type(:json) }
862
- it { should respond_with_json(I18n.t('bigbluebutton_rails.rooms.notice.end.not_running')) }
863
- end
864
-
865
- context "throwing an exception" do
866
- let(:msg) { "any error message" }
867
- before {
868
- mocked_api.should_receive(:is_meeting_running?).and_return{ raise BigBlueButton::BigBlueButtonException.new(msg) }
869
- }
870
- before(:each) { get :end, :server_id => mocked_server.to_param, :id => room.to_param, :format => 'json' }
871
- it { should respond_with(:error) }
872
- it { should respond_with_content_type(:json) }
873
- it { should respond_with_json(msg) }
651
+ it { should render_template(:external) }
652
+ it { should set_the_flash.to(I18n.t('bigbluebutton_rails.rooms.errors.auth.not_running')) }
874
653
  end
875
654
 
876
655
  end
877
656
 
878
- describe "#destroy" do
879
- before { mock_server_and_api }
657
+ end # #external_auth
880
658
 
881
- context "on success" do
882
- before {
883
- mocked_api.should_receive(:is_meeting_running?).and_return(true)
884
- mocked_api.should_receive(:end_meeting)
885
- }
886
- before(:each) {
887
- delete :destroy, :server_id => mocked_server.to_param, :id => room.to_param, :format => 'json'
888
- }
889
- it { should respond_with(:success) }
890
- it { should respond_with_content_type(:json) }
891
- it {
892
- json = { :message => I18n.t('bigbluebutton_rails.rooms.notice.destroy.success') }.to_json
893
- should respond_with_json(json)
894
- }
895
- end
896
-
897
- context "throwing error" do
898
- let(:msg) { "any error message" }
899
- before {
900
- mocked_api.should_receive(:is_meeting_running?).and_return{ raise BigBlueButton::BigBlueButtonException.new(msg) }
901
- }
902
- before(:each) {
903
- delete :destroy, :server_id => mocked_server.to_param, :id => room.to_param, :format => 'json'
904
- }
905
- it { should respond_with(:error) }
906
- it { should respond_with_content_type(:json) }
907
- it { should respond_with_json({ :message => msg }.to_json) }
908
- end
909
- end
659
+ # can be used when matching rooms inside some resource other than servers
660
+ context "selects the first server when the server_id is not defined in the url" do
661
+ let(:server2) { Factory.create(:bigbluebutton_server) }
910
662
 
911
- end # json responses
663
+ # get /users/:user_id/room/:id(.:format)
664
+ before(:each) { get :show, :id => room.to_param, :user_id => "1" }
665
+ it { should respond_with(:success) }
666
+ it { should assign_to(:server).with(server) }
667
+ end
912
668
 
913
669
  end
914
670