<commit_before>require 'spec_helper'

describe UnfinishedStoriesController do

  describe "GET #show" do

    context "when user logged in" do
      
      let(:current_user) do
        User.create!(username: 'Dr. Seuss', email: '<EMAIL>', password: '<PASSWORD>')
      end

      before do
        sign_in current_user
      end

      context "when there is an unfinished story for another user" do 
        it "redirects to that story" do
          another_user = User.create!(username: 'Dude Looks Like a Lady', email: '<EMAIL>', password: 'password')
          unfinished_story = Story.create!(title: 'Once upon a time', first_entry: 'whatever', user_id: another_user.id)
          unfinished_story.entries.create!(body: 'Geese are a great alarm clock')
          get :show
          expect(response).to redirect_to(unfinished_story)
        end

      end

      context "when there is an unfinished story for current user" do
        it "redirects to the new story page" do
          relevant = Story.create!(title: 'The Places You Will Go', first_entry: 'Paris', user_id: current_user.id)
          get :show
          expect(response).to redirect_to(new_story_path)
        end
      end

      context "when there are no unfinished stories" do
        before do
          get :show
        end

        it "redirects to the new story page" do
          expect(response).to redirect_to(new_story_path)
        end

        it "tells the user there are no unfinished stories" do
          expect(flash[:notice]).to eq("Sorry, no unfinished stories to add to right now.")
        end
      end

    end

    context "when no user is logged in" do
    end
  end

end<commit_msg>Adding test for unfinished story when user is not logged in<commit_after>require 'spec_helper'

describe UnfinishedStoriesController do

  describe "GET #show" do

    context "when user logged in" do

      let(:current_user) do
        User.create!(username: 'Dr. Seuss', email: '<EMAIL>', password: '<PASSWORD>!sh')
      end

      before do
        sign_in current_user
      end

      context "when there is an unfinished story for another user" do 
        it "redirects to that story" do
          another_user = User.create!(username: 'Dude Looks Like a Lady', email: '<EMAIL>', password: 'password')
          unfinished_story = Story.create!(title: 'Once upon a time', first_entry: 'whatever', user_id: another_user.id)
          unfinished_story.entries.create!(body: 'Geese are a great alarm clock')
          get :show
          expect(response).to redirect_to(unfinished_story)
        end

      end

      context "when there is an unfinished story for current user" do
        it "redirects to the new story page" do
          relevant = Story.create!(title: 'The Places You Will Go', first_entry: 'Paris', user_id: current_user.id)
          get :show
          expect(response).to redirect_to(new_story_path)
        end
      end

      context "when there are no unfinished stories" do
        before do
          get :show
        end

        it "redirects to the new story page" do
          expect(response).to redirect_to(new_story_path)
        end

        it "tells the user there are no unfinished stories" do
          expect(flash[:notice]).to eq("Sorry, no unfinished stories to add to right now.")
        end
      end

    end

    context "when no user is logged in" do
      it "redirects to login page" do
        get :show
        expect(response).to redirect_to(new_user_session_path)
      end
    end
  end

end
{'fraction_non_alphanumeric': 0.0788135593220339, 'fraction_numerical': 0.0, 'mean_word_length': 2.4015369836695486, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7055337', 'n_tokens_mistral': 1000, 'n_tokens_neox': 960, 'n_words': 370}