require 'spec_helper'

describe IcecastMountTemplate do

  let(:mount_template) { template = FactoryGirl.create(:icecast_mount_template) }

  it "save" do
    mount_template.errors.any?.should be_false
  end

  describe "poke configs" do
    let(:server) { a = FactoryGirl.create(:icecast_server_with_overrides); a.config_updated; IcecastServer.find(a.id) }
    let(:music_session) { FactoryGirl.create(:active_music_session, :fan_access => true)}

    before(:each) do
      server.touch
      mount = IcecastMount.build_session_mount(music_session.music_session, music_session, IcecastServer.find_best_server_for_user(music_session.creator))
      mount.save!
      server.save!
      server.config_updated
      server.reload
      server.config_changed.should == 0
    end

    it "success via server" do
      server.mounts.first.mount_template.save!
      server.reload
      server.config_changed.should == 1
    end

    it "delete via server" do
      server.mounts.first.mount_template.destroy
      server.reload
      server.config_changed.should == 1
    end
  end
end
