109 lines
4.3 KiB
Ruby
109 lines
4.3 KiB
Ruby
require 'spec_helper'
|
|
|
|
describe Track do
|
|
|
|
let (:user) {FactoryGirl.create(:user) }
|
|
let (:music_session) { FactoryGirl.create(:active_music_session, :creator => user)}
|
|
let (:connection) { FactoryGirl.create(:connection, :user => user, :music_session => music_session) }
|
|
let (:track) { FactoryGirl.create(:track, :connection => connection)}
|
|
let (:track2) { FactoryGirl.create(:track, :connection => connection)}
|
|
let (:msuh) {FactoryGirl.create(:music_session_user_history, :history => music_session.music_session, :user => user, :client_id => connection.client_id) }
|
|
let (:track_hash) { {:client_track_id => 'client_guid', :sound => 'stereo', :instrument_id => 'drums'} }
|
|
|
|
before(:each) do
|
|
msuh.touch
|
|
end
|
|
|
|
describe "sync" do
|
|
it "create one track" do
|
|
tracks = Track.sync(connection.client_id, [track_hash])
|
|
tracks.length.should == 1
|
|
track = tracks[0]
|
|
track.client_track_id.should == track_hash[:client_track_id]
|
|
track.sound = track_hash[:sound]
|
|
track.instrument.should == Instrument.find('drums')
|
|
end
|
|
|
|
it "create two tracks" do
|
|
tracks = Track.sync(connection.client_id, [track_hash, track_hash])
|
|
tracks.length.should == 2
|
|
track = tracks[0]
|
|
track.client_track_id.should == track_hash[:client_track_id]
|
|
track.sound = track_hash[:sound]
|
|
track.instrument.should == Instrument.find('drums')
|
|
track = tracks[1]
|
|
track.client_track_id.should == track_hash[:client_track_id]
|
|
track.sound = track_hash[:sound]
|
|
track.instrument.should == Instrument.find('drums')
|
|
end
|
|
|
|
it "delete only track" do
|
|
track.id.should_not be_nil
|
|
connection.tracks.length.should == 1
|
|
tracks = Track.sync(connection.client_id, [])
|
|
tracks.length.should == 0
|
|
end
|
|
|
|
it "delete one of two tracks using .id to correlate" do
|
|
|
|
track.id.should_not be_nil
|
|
track2.id.should_not be_nil
|
|
connection.tracks.length.should == 2
|
|
tracks = Track.sync(connection.client_id, [{:id => track.id, :client_track_id => 'client_guid_new', :sound => 'mono', :instrument_id => 'drums'}])
|
|
tracks.length.should == 1
|
|
found = tracks[0]
|
|
found.id.should == track.id
|
|
found.sound.should == 'mono'
|
|
found.client_track_id.should == 'client_guid_new'
|
|
end
|
|
|
|
it "delete one of two tracks using .client_track_id to correlate" do
|
|
|
|
track.id.should_not be_nil
|
|
track2.id.should_not be_nil
|
|
connection.tracks.length.should == 2
|
|
tracks = Track.sync(connection.client_id, [{:client_track_id => track.client_track_id, :sound => 'mono', :instrument_id => 'drums'}])
|
|
tracks.length.should == 1
|
|
found = tracks[0]
|
|
found.id.should == track.id
|
|
found.sound.should == 'mono'
|
|
found.client_track_id.should == track.client_track_id
|
|
end
|
|
|
|
|
|
it "updates a single track using .id to correlate" do
|
|
track.id.should_not be_nil
|
|
connection.tracks.length.should == 1
|
|
set_updated_at(track, 1.days.ago)
|
|
tracks = Track.sync(connection.client_id, [{:id => track.id, :client_track_id => 'client_guid_new', :sound => 'mono', :instrument_id => 'drums'}])
|
|
tracks.length.should == 1
|
|
found = tracks[0]
|
|
found.id.should == track.id
|
|
found.sound.should == 'mono'
|
|
found.client_track_id.should == 'client_guid_new'
|
|
found.updated_at.should_not == track.updated_at
|
|
end
|
|
|
|
it "updates a single track using .client_track_id to correlate" do
|
|
track.id.should_not be_nil
|
|
connection.tracks.length.should == 1
|
|
tracks = Track.sync(connection.client_id, [{:client_track_id => track.client_track_id, :sound => 'mono', :instrument_id => 'drums'}])
|
|
tracks.length.should == 1
|
|
found = tracks[0]
|
|
found.id.should == track.id
|
|
found.sound.should == 'mono'
|
|
found.client_track_id.should == track.client_track_id
|
|
end
|
|
|
|
it "does not touch updated_at when nothing changes" do
|
|
track.id.should_not be_nil
|
|
connection.tracks.length.should == 1
|
|
set_updated_at(track, 1.days.ago)
|
|
tracks = Track.sync(connection.client_id, [{:id => track.id, :client_track_id => track.client_track_id, :sound => track.sound, :instrument_id => track.instrument_id, client_resource_id: track.client_resource_id}])
|
|
tracks.length.should == 1
|
|
found = tracks[0]
|
|
expect(found.id).to eq track.id
|
|
expect(found.updated_at.to_i).to eq track.updated_at.to_i
|
|
end
|
|
end
|
|
end |