Merge branch 'develop' of bitbucket.org:jamkazam/jam-cloud into develop
This commit is contained in:
commit
937695e829
|
|
@ -231,3 +231,4 @@ shopping_carts.sql
|
|||
recurly.sql
|
||||
add_track_resource_id.sql
|
||||
user_genres.sql
|
||||
user_online.sql
|
||||
|
|
|
|||
|
|
@ -0,0 +1,25 @@
|
|||
-- this was patched on the server without a proper migration, so the migration script here takes care to make sure it can run 2x
|
||||
ALTER TABLE users DROP COLUMN IF EXISTS online;
|
||||
DROP TRIGGER IF EXISTS connection_up_down ON connections;
|
||||
|
||||
ALTER TABLE users ADD COLUMN online BOOL DEFAULT FALSE NOT NULL;
|
||||
|
||||
CREATE OR REPLACE FUNCTION manage_user_online() RETURNS TRIGGER
|
||||
STRICT VOLATILE AS $$
|
||||
BEGIN
|
||||
IF (TG_OP = 'DELETE') THEN
|
||||
UPDATE users set ONLINE = (SELECT COUNT(conn.id) FROM connections conn WHERE conn.user_id = OLD.user_id) > 0 WHERE users.id = OLD.user_id;
|
||||
RETURN NULL;
|
||||
ELSIF (TG_OP = 'INSERT') THEN
|
||||
UPDATE users set ONLINE = (SELECT COUNT(conn.id) FROM connections conn WHERE conn.user_id = NEW.user_id) > 0 WHERE users.id = NEW.user_id;
|
||||
RETURN NULL;
|
||||
END IF;
|
||||
RETURN NULL;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
CREATE TRIGGER connection_up_down AFTER INSERT OR DELETE
|
||||
ON connections FOR EACH ROW EXECUTE PROCEDURE manage_user_online(user_id);
|
||||
|
||||
-- ONE time bootstrap the new online field
|
||||
UPDATE users set online = (SELECT COUNT(conn.id) FROM connections conn WHERE conn.user_id = users.id) > 0;
|
||||
|
|
@ -8,3 +8,4 @@ Once you've created your database, migrate it:
|
|||
`bundle exec jam_ruby up`
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -267,7 +267,7 @@ module JamRuby
|
|||
|
||||
notification_msg = format_msg(notification.description, {:user => user})
|
||||
|
||||
if friend.online
|
||||
if friend.online?
|
||||
msg = @@message_factory.friend_request(
|
||||
friend.id,
|
||||
friend_request_id,
|
||||
|
|
|
|||
|
|
@ -253,7 +253,7 @@ module JamRuby
|
|||
end
|
||||
|
||||
def online
|
||||
@online ||= !self.connections.nil? && self.connections.size > 0
|
||||
online?
|
||||
end
|
||||
|
||||
def name
|
||||
|
|
|
|||
|
|
@ -103,4 +103,79 @@ describe JamRuby::Connection do
|
|||
end
|
||||
end
|
||||
|
||||
describe "triggers" do
|
||||
describe "manage_user_online" do
|
||||
it "offline for new user" do
|
||||
user.online.should be_false
|
||||
end
|
||||
|
||||
it "online/offline based on connection up/down" do
|
||||
conn.touch # make a connection
|
||||
user.reload
|
||||
user.online.should be_true
|
||||
|
||||
conn.delete
|
||||
user.reload
|
||||
user.online.should be_false
|
||||
end
|
||||
|
||||
it "verify that online up/down is only for affected user (no spillover)" do
|
||||
user2 = FactoryGirl.create(:user)
|
||||
user2.online.should be_false
|
||||
|
||||
conn.touch
|
||||
user.reload
|
||||
user2.reload
|
||||
|
||||
user.online.should be_true
|
||||
user2.online.should be_false # make sure there is no spillover to unrelated users
|
||||
|
||||
conn2 = FactoryGirl.create(:connection,
|
||||
:user => user2,
|
||||
:music_session => music_session,
|
||||
:ip_address => "1.1.1.1",
|
||||
:client_id => "2")
|
||||
|
||||
user.reload
|
||||
user2.reload
|
||||
|
||||
user.online.should be_true
|
||||
user2.online.should be_true
|
||||
|
||||
# whack one of the connections
|
||||
conn.delete
|
||||
user.reload
|
||||
user2.reload
|
||||
user.online.should be_false
|
||||
user2.online.should be_true
|
||||
|
||||
conn2.delete
|
||||
user.reload
|
||||
user2.reload
|
||||
user.online.should be_false
|
||||
user2.online.should be_false
|
||||
end
|
||||
|
||||
it "n connections" do
|
||||
conn.touch
|
||||
conn2 = FactoryGirl.create(:connection,
|
||||
:user => user,
|
||||
:music_session => music_session,
|
||||
:ip_address => "1.1.1.1",
|
||||
:client_id => "2")
|
||||
|
||||
user.reload
|
||||
user.online.should be_true
|
||||
|
||||
conn.delete
|
||||
user.reload
|
||||
user.online.should be_true
|
||||
|
||||
conn2.delete
|
||||
user.reload
|
||||
user.online.should be_false
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -779,6 +779,7 @@ describe Notification do
|
|||
|
||||
it "success when online" do
|
||||
receiver_connection = FactoryGirl.create(:connection, user: @receiver)
|
||||
@receiver.reload
|
||||
message = "Just a test message!"
|
||||
calls = count_publish_to_user_calls
|
||||
notification = Notification.send_text_message(message, @sender, @receiver)
|
||||
|
|
@ -796,6 +797,7 @@ describe Notification do
|
|||
|
||||
it "success when online with long message" do
|
||||
receiver_connection = FactoryGirl.create(:connection, user: @receiver)
|
||||
@receiver.reload
|
||||
message = "0" * 203 # 200 is clip size
|
||||
calls = count_publish_to_user_calls
|
||||
notification = Notification.send_text_message(message, @sender, @receiver)
|
||||
|
|
|
|||
|
|
@ -211,7 +211,7 @@ describe "Bands", :js => true, :type => :feature, :capybara_feature => true do
|
|||
view_band_profile_of some_band
|
||||
expect(page).to have_selector('#band-profile-follower-stats', text: "1 Follower")
|
||||
find('#band-profile-social-link').trigger(:click)
|
||||
expect(page).to have_selector('div.profile-block-name')
|
||||
expect(page).to have_selector('div.band-profile-block-name')
|
||||
end
|
||||
|
||||
end
|
||||
|
|
@ -225,7 +225,7 @@ describe "Bands", :js => true, :type => :feature, :capybara_feature => true do
|
|||
expect(page).to have_selector('#btn-edit-band-profile')
|
||||
|
||||
find('#btn-edit-band-profile').trigger(:click)
|
||||
find('h2', text: 'Step 1: General Information')
|
||||
find('h2', text: 'General Information')
|
||||
|
||||
expect(page).to have_content band.name
|
||||
expect(page).to have_content band.biography
|
||||
|
|
|
|||
Loading…
Reference in New Issue