require 'spec_helper' describe ApiUsersController do render_views let (:user) { FactoryGirl.create(:user) } let (:conn) { FactoryGirl.create(:connection, user: user, last_jam_audio_latency: 5) } before(:each) do controller.current_user = user end describe "update mod" do it "empty mod" do post :update, id:user.id, mods: {}, :format=>'json' response.should be_success user.mods_json.should == {} end it "no_show mod" do user_id = user.id mods = {"no_show" => {"something1" => true}} post :update, id:user.id, mods: mods, :format=>'json' response.should be_success # verify that the user object has the mods data user_again = User.find(user_id) user_again.mods_json.should == mods # verify that the response shows the mods structure json = JSON.parse(response.body) json["mods"].should == mods end end describe "audio_latency" do it "updates both connection and user" do post :audio_latency, id: user.id, client_id: conn.client_id, audio_latency: 3.5, :format => 'json' response.should be_success conn.reload conn.last_jam_audio_latency.should == 3.5 user.reload conn.user.last_jam_audio_latency.should == 3.5 end it "if connection does not exist, user is still updated" do post :audio_latency, id: user.id, client_id: 'nothingness', audio_latency: 3.5, :format => 'json' response.should be_success user.reload conn.user.last_jam_audio_latency.should == 3.5 end it "ignores latencies of 2 or less" do post :audio_latency, id: user.id, client_id: conn.client_id, audio_latency: 2, :format => 'json' response.should be_success conn.reload conn.last_jam_audio_latency.should == 5 user.reload conn.user.last_jam_audio_latency.should == 5 end end end