require 'spec_helper' describe "Welcome", :js => true, :type => :feature, :capybara_feature => true do subject { page } before(:all) do Capybara.javascript_driver = :poltergeist Capybara.current_driver = Capybara.javascript_driver Capybara.default_wait_time = 10 end before(:each) do Feed.delete_all MusicSessionUserHistory.delete_all MusicSession.delete_all Recording.delete_all emulate_client visit "/" find('h1', text: 'Play music together over the Internet as if in the same room') end let(:user) { FactoryGirl.create(:user) } let(:fb_auth) { { :provider => "facebook", :uid => "1234", :info => {:name => "John Doe", :email => "johndoe@email.com"}, :credentials => {:token => "testtoken234tsdf", :expires_at => 2391456019}, :extra => { :raw_info => {:first_name => 'John', :last_name => 'Doe', :email => 'facebook@jamkazam.com', :gender => 'male'}} } } describe "signin" do before(:each) do find('#signin').trigger(:click) end it "show dialog" do should have_selector('h1', text: 'sign in') end it "shows signup dialog if selected" do find('.show-signup-dialog').trigger(:click) find('h1', text: 'sign up for jamkazam') end it "forgot password" do find('a.forgot-password').trigger(:click) find('h1', text: 'reset your password') end it "closes if cancelled" do find('a.signin-cancel').trigger(:click) should_not have_selector('h1', text: 'sign in') end describe "signin natively" do it "redirects to client on login" do within('.signin-form') do fill_in "Email Address:", with: user.email fill_in "Password:", with: user.password click_button "SIGN IN" end wait_until_curtain_gone find('h2', text: 'musicians') end it "shows error if bad login" do within('.signin-form') do fill_in "Email Address:", with: "junk" fill_in "Password:", with: user.password click_button "SIGN IN" end should have_selector('h1', text: 'sign in') find('div.login-error-msg', text: 'Invalid login') end end describe "redirect-to" do it "redirect on login" do visit "/client#/account" find('.curtain') find('h1', text: 'sign in or register') within('.signin-form') do fill_in "Email Address:", with: user.email fill_in "Password:", with: user.password click_button "SIGN IN" end wait_until_curtain_gone find('h2', text: 'identity:') end it "redirect if already logged in" do # this is a rare case sign_in_poltergeist(user) visit "/?redirect-to=" + ERB::Util.url_encode("/client#/account") find('h1', text: 'Play music together over the Internet as if in the same room') find('#signin').trigger(:click) wait_until_curtain_gone find('h2', text: 'identity:') end end describe "signin with facebook" do before(:each) do user.user_authorizations.build provider: 'facebook', uid: '1234', token: 'abc', token_expiration: 1.days.from_now user.save! OmniAuth.config.mock_auth[:facebook] = OmniAuth::AuthHash.new(fb_auth) end it "click will redirect to facebook for authorization" do find('.signin-facebook').trigger(:click) wait_until_curtain_gone find('h2', text: 'musicians') end end end describe "signup" do before(:each) do find('#signup').trigger(:click) end it "show dialog" do should have_selector('h1', text: 'sign up for jamkazam') end it "shows signin dialog if selected" do find('.show-signin-dialog').trigger(:click) find('h1', text: 'sign in') end it "closes if cancelled" do find('a.signup-cancel').trigger(:click) should_not have_selector('h1', text: 'sign in') end describe "signup with email" do it "click will redirect to signup page" do find('.signup-email').trigger(:click) find('h2', text: 'Create a JamKazam account') end end describe "signup with facebook" do before(:each) do fb_auth[:uid] = '12345' OmniAuth.config.mock_auth[:facebook] = OmniAuth::AuthHash.new(fb_auth) end it "click will redirect to facebook for authorization" do find('.signup-facebook').trigger(:click) find('h2', text: 'Create a JamKazam account') find_field('jam_ruby_user[first_name]').value.should eq 'John' find_field('jam_ruby_user[last_name]').value.should eq 'Doe' find_field('jam_ruby_user[email]').value.should eq 'facebook@jamkazam.com' end end end describe "feed" do it "data" do claimedRecording1 = FactoryGirl.create(:claimed_recording) MusicSession1 = claimedRecording1.recording.music_session.music_session visit "/" find('h1', text: 'Play music together over the Internet as if in the same room') find('.feed-entry.music-session-history-entry .description', text: MusicSession1.description) find('.feed-entry.music-session-history-entry .session-status', text: 'BROADCASTING OFFLINE') find('.feed-entry.music-session-history-entry .session-controls.inprogress', text: 'BROADCASTING OFFLINE') find('.feed-entry.music-session-history-entry .artist', text: MusicSession1.creator.name) should_not have_selector('.feed-entry.music-session-history-entry .musician-detail') find('.feed-entry.recording-entry .name', text: claimedRecording1.name) find('.feed-entry.recording-entry .description', text: claimedRecording1.description) find('.feed-entry.recording-entry .title', text: 'RECORDING') find('.feed-entry.recording-entry .artist', text: claimedRecording1.user.name) should_not have_selector('.feed-entry.recording-entry .musician-detail') # try to hide the recording claimedRecording1.is_public = false claimedRecording1.save! visit "/" find('h1', text: 'Play music together over the Internet as if in the same room') find('.feed-entry.music-session-history-entry .description', text: MusicSession1.description) should_not have_selector('.feed-entry.recording-entry') # try to hide the music session MusicSession1.fan_access = false MusicSession1.save! visit "/" find('h1', text: 'Play music together over the Internet as if in the same room') should have_selector('.feed-entry.music-session-history-entry') # try to mess with the music session history by removing all user histories (which makes it a bit invalid) # but we really don't want the front page to ever crash if we can help it MusicSession1.fan_access = true MusicSession1.music_session_user_histories.delete_all MusicSession1.reload MusicSession1.music_session_user_histories.length.should == 0 visit "/" find('h1', text: 'Play music together over the Internet as if in the same room') should_not have_selector('.feed-entry.music-session-history-entry') end end end