Skip to content

Commit

Permalink
After fetch_meetings all rooms are automatically saved in the DB if t…
Browse files Browse the repository at this point in the history
…hey are not there yet.

Also created the mechanism and migration file to migrate to the next gem version.
  • Loading branch information
daronco committed Jun 12, 2011
1 parent e58fe33 commit 02b472f
Show file tree
Hide file tree
Showing 12 changed files with 106 additions and 29 deletions.
3 changes: 2 additions & 1 deletion app/models/bigbluebutton_room.rb
Expand Up @@ -23,7 +23,8 @@ class BigbluebuttonRoom < ActiveRecord::Base

attr_accessible :name, :server_id, :meetingid, :attendee_password, :moderator_password,
:welcome_msg, :owner, :server, :private, :logout_url, :dial_number,
:voice_bridge, :max_participants, :owner_id, :owner_type, :randomize_meetingid
:voice_bridge, :max_participants, :owner_id, :owner_type, :randomize_meetingid,
:external

# Note: these params need to be fetched from the server before being accessed
attr_accessor :running, :participant_count, :moderator_count, :attendees,
Expand Down
11 changes: 7 additions & 4 deletions app/models/bigbluebutton_server.rb
Expand Up @@ -43,14 +43,17 @@ def fetch_meetings
response[:meetings].each do |attr|
room = BigbluebuttonRoom.find_by_server_id_and_meetingid(self.id, attr[:meetingID])
if room.nil?
room = BigbluebuttonRoom.new(:server => self, :meetingid => attr[:meetingID], :name => attr[:meetingID],
:attendee_password => attr[:attendeePW], :moderator_password => attr[:moderatorPW])
room.running = attr[:running]
room = BigbluebuttonRoom.new(:server => self, :meetingid => attr[:meetingID],
:name => attr[:meetingID], :attendee_password => attr[:attendeePW],
:moderator_password => attr[:moderatorPW], :external => true)
room.save
else
room.update_attributes(:attendee_password => attr[:attendeePW],
:moderator_password => attr[:moderatorPW])
room.running = attr[:running]
end
room.running = attr[:running]

# TODO What if the update/save above fails?

@meetings << room
end
Expand Down
4 changes: 4 additions & 0 deletions app/views/bigbluebutton/rooms/_form.html.erb
Expand Up @@ -60,6 +60,10 @@
<%= f.label :max_participants %><br />
<%= f.text_field :max_participants %>
</div>
<div class="field">
<%= f.label :external %><br />
<%= f.check_box :external %>
</div>
<div class="actions">
<%= f.submit %>
</div>
Expand Down
2 changes: 2 additions & 0 deletions app/views/bigbluebutton/rooms/index.html.erb
Expand Up @@ -14,6 +14,7 @@
<th><%= BigbluebuttonRoom.human_attribute_name(:dial_number) %></th>
<th><%= BigbluebuttonRoom.human_attribute_name(:voice_bridge) %></th>
<th><%= BigbluebuttonRoom.human_attribute_name(:max_participants) %></th>
<th><%= BigbluebuttonRoom.human_attribute_name(:external) %></th>
<th></th>
<th></th>
<th></th>
Expand All @@ -33,6 +34,7 @@
<td><%= room.dial_number %></td>
<td><%= room.voice_bridge %></td>
<td><%= room.max_participants %></td>
<td><%= room.external %></td>
<td><%= link_to 'Show', bigbluebutton_server_room_path(@server, room) %></td>
<td><%= link_to 'Edit', edit_bigbluebutton_server_room_path(@server, room) %></td>
<td><%= link_to 'Destroy', bigbluebutton_server_room_path(@server, room), :confirm => 'Are you sure?', :method => :delete %></td>
Expand Down
4 changes: 4 additions & 0 deletions app/views/bigbluebutton/rooms/show.html.erb
Expand Up @@ -50,6 +50,10 @@
<b><%= BigbluebuttonRoom.human_attribute_name(:max_participants) %>:</b>
<%= @room.max_participants %>
</p>
<p>
<b><%= BigbluebuttonRoom.human_attribute_name(:external) %>:</b>
<%= @room.external %>
</p>

<%= link_to 'Edit', edit_bigbluebutton_server_room_path(@room.server, @room) %> |
<%= link_to 'Back', bigbluebutton_server_rooms_path(@room.server) %>
Expand Down
1 change: 1 addition & 0 deletions config/locales/en.yml
Expand Up @@ -50,4 +50,5 @@ en:
dial_number: "Dial Number"
voice_bridge: "Voice Bridge"
max_participants: "Maximum Number of Participants"
external: "Creted by another system"

17 changes: 14 additions & 3 deletions lib/generators/bigbluebutton_rails/install_generator.rb
Expand Up @@ -4,21 +4,32 @@ module BigbluebuttonRails
module Generators
class InstallGenerator < Rails::Generators::Base
include Rails::Generators::Migration
argument :migrate_to_version, :type => :string, :default => "", :description => "Generate migration to this version"
class_option :locale, :type => :boolean, :default => true, :description => "Include locale file"
source_root File.expand_path("../templates", __FILE__)

desc "Creates the initializer, initial migration and locale files."
desc "Creates the migrations and locale files. Also used to create migrations when updating the gem version."

def copy_locale
# uses bigbluebutton_rails/config to avoid using the local application en.yml
copy_file "../../../../../bigbluebutton_rails/config/locales/en.yml", "config/locales/bigbluebutton_rails.en.yml"
copy_file "../../../../../bigbluebutton_rails/config/locales/en.yml", "config/locales/bigbluebutton_rails.en.yml" if options.locale?
end

def self.next_migration_number(dirname)
ActiveRecord::Generators::Base.next_migration_number(dirname)
end

def create_migration_file
migration_template 'migration.rb', 'db/migrate/create_bigbluebutton_rails.rb'
if migrate_to_version.blank?
migration_template 'migration.rb', 'db/migrate/create_bigbluebutton_rails.rb'
else
migration_template "migration_#{version_filename}.rb", "db/migrate/bigbluebutton_rails_to_#{version_filename}.rb"
end
end

protected
def version_filename
migrate_to_version.gsub(".", "_")
end

end
Expand Down
1 change: 1 addition & 0 deletions lib/generators/bigbluebutton_rails/templates/migration.rb
Expand Up @@ -23,6 +23,7 @@ def self.up
t.integer :max_participants
t.boolean :private, :default => false
t.boolean :randomize_meetingid, :default => true
t.boolean :external, :default => false
t.timestamps
end
add_index :bigbluebutton_rooms, :server_id
Expand Down
11 changes: 11 additions & 0 deletions lib/generators/bigbluebutton_rails/templates/migration_0_0_5.rb
@@ -0,0 +1,11 @@
class BigbluebuttonRailsTo005 < ActiveRecord::Migration

def self.up
add_column :bigbluebutton_rooms, :external, :boolean, :default => false
end

def self.down
remove_column :bigbluebutton_rooms, :external
end

end
56 changes: 46 additions & 10 deletions spec/generators/install_generator_spec.rb
Expand Up @@ -5,19 +5,55 @@
destination File.expand_path("../../../tmp", __FILE__)
tests BigbluebuttonRails::Generators::InstallGenerator

before(:all) do
prepare_destination
run_generator
context "standard install" do
before(:all) do
prepare_destination
run_generator
end

it "all files are properly created" do
assert_migration "db/migrate/create_bigbluebutton_rails.rb"
assert_file "config/locales/bigbluebutton_rails.en.yml"
end

it "all files are properly destroyed" do
run_generator %w(), :behavior => :revoke
assert_no_file "config/locales/bigbluebutton_rails.en.yml"
assert_no_migration "db/migrate/create_bigbluebutton_rails.rb"
end
end

it "all files are properly created" do
assert_migration "db/migrate/create_bigbluebutton_rails.rb"
assert_file "config/locales/bigbluebutton_rails.en.yml"
context "without locale" do
before(:all) do
prepare_destination
run_generator %w{ --skip-locale }
end

it "all files are properly created" do
assert_migration "db/migrate/create_bigbluebutton_rails.rb"
assert_no_file "config/locales/bigbluebutton_rails.en.yml"
end
end

it "all files are properly destroyed" do
run_generator %w(), :behavior => :revoke
assert_no_file "config/locales/bigbluebutton_rails.en.yml"
assert_no_migration "db/migrate/create_bigbluebutton_rails.rb"
context "migrating to version" do
before { prepare_destination }

["0.0.5"].each do |version|
context "#{version}" do
before { run_generator [ version ] }

it "all files are properly created" do
assert_migration "db/migrate/bigbluebutton_rails_to_#{version.gsub(".", "_")}.rb"
assert_file "config/locales/bigbluebutton_rails.en.yml"
end

it "all files are properly destroyed" do
run_generator [ version ], :behavior => :revoke
assert_no_file "config/locales/bigbluebutton_rails.en.yml"
assert_no_migration "db/migrate/bigbluebutton_rails_to_#{version.gsub(".", "_")}.rb"
end
end
end
end

end
12 changes: 5 additions & 7 deletions spec/models/bigbluebutton_room_spec.rb
Expand Up @@ -21,17 +21,16 @@
it { should have_db_column(:max_participants).of_type(:integer) }
it { should have_db_column(:private).of_type(:boolean) }
it { should have_db_column(:randomize_meetingid).of_type(:boolean) }
it { should have_db_column(:external).of_type(:boolean) }
it { should have_db_index(:server_id) }
it { should have_db_index(:meetingid).unique(true) }
it { should have_db_index(:voice_bridge).unique(true) }
it {
it "default values" do
room = BigbluebuttonRoom.new
room.private.should be_false
}
it {
room = BigbluebuttonRoom.new
room.randomize_meetingid.should be_true
}
room.external.should be_false
end
end

context do
Expand All @@ -48,7 +47,6 @@
it { should validate_presence_of(:voice_bridge) }
it { should validate_presence_of(:name) }


it { should be_boolean(:private) }
it { should be_boolean(:randomize_meetingid) }

Expand Down Expand Up @@ -77,7 +75,7 @@

# attr_accessors
[:running, :participant_count, :moderator_count, :attendees,
:has_been_forcibly_ended, :start_time, :end_time].each do |attr|
:has_been_forcibly_ended, :start_time, :end_time, :external].each do |attr|
it { should respond_to(attr) }
it { should respond_to("#{attr}=") }
end
Expand Down
13 changes: 9 additions & 4 deletions spec/models/bigbluebutton_server_spec.rb
Expand Up @@ -110,9 +110,9 @@
# the hashes should be exactly as returned by bigbluebutton-api-ruby to be sure we are testing it right
let(:meetings) {
[
{ :meetingID => room1.meetingid, :attendeePW=>"ap", :moderatorPW=>"mp", :hasBeenForciblyEnded => false, :running => true},
{ :meetingID => room2.meetingid, :attendeePW=>"pass", :moderatorPW=>"pass", :hasBeenForciblyEnded => true, :running => false},
{ :meetingID => "im not in the db", :attendeePW=>"pass", :moderatorPW=>"pass", :hasBeenForciblyEnded => true, :running => true}
{ :meetingID => room1.meetingid, :attendeePW => "ap", :moderatorPW => "mp", :hasBeenForciblyEnded => false, :running => true},
{ :meetingID => room2.meetingid, :attendeePW => "pass", :moderatorPW => "pass", :hasBeenForciblyEnded => true, :running => false},
{ :meetingID => "im not in the db", :attendeePW => "pass", :moderatorPW => "pass", :hasBeenForciblyEnded => true, :running => true}
]
}
let(:hash) {
Expand All @@ -134,18 +134,23 @@
server.meetings[0].attendee_password.should == "ap"
server.meetings[0].moderator_password.should == "mp"
server.meetings[0].running.should == true
server.meetings[0].new_record?.should be_false
server.meetings[0].external.should be_false

server.meetings[1].should == room2
server.meetings[1].attendee_password.should == "pass"
server.meetings[1].moderator_password.should == "pass"
server.meetings[1].running.should == false
server.meetings[1].new_record?.should be_false
server.meetings[1].external.should be_false

server.meetings[2].meetingid.should == "im not in the db"
server.meetings[2].server.should == server
server.meetings[2].new_record?.should be_true
server.meetings[2].attendee_password.should == "pass"
server.meetings[2].moderator_password.should == "pass"
server.meetings[2].running.should == true
server.meetings[2].new_record?.should be_false
server.meetings[2].external.should be_true
end

end
Expand Down

0 comments on commit 02b472f

Please sign in to comment.