<commit_before>require 'spec_helper'

describe 'Articles pages' do

  subject { page }

  describe 'for anonymous users' do

    describe 'in the index page' do
      before { visit articles_path }

      it { should have_page_title 'Articles' }
      it { should_not have_page_heading 'Post article' }
    end
  end

  describe 'for signed-in users' do

    describe 'as a regular user' do

      before do
        @user = Fabricate(:user)
        visit new_user_session_path
        capybara_signin(@user)
      end

      describe 'in the index page' do

        before { visit articles_path }

        it { should have_page_title 'Articles' }
        it { should have_page_heading 'Articles' }
        it { should_not have_link 'New article' }
        it { should_not have_link 'Edit' }
        it { should_not have_link 'Destroy' }
      end

      describe 'in the show page' do

        before do
          @article = Fabricate(:article)
          visit article_path(@article)
        end

        it { should have_page_title @article.title }
        it { should have_page_heading @article.title }
        it { should have_link 'Back to articles' }
        it { should_not have_link 'Edit' }
        it { should_not have_link 'Destroy' }
      end

      describe 'in the new page' do

        before { visit new_article_path }

        it { should have_error_message 'Access denied' }
        it { should have_page_title '' }
        it { should have_page_heading 'Developers Connect' }
      end

      describe 'in the edit page' do

        before do
          @article = Fabricate(:article)
          visit edit_article_path(@article)
        end

        it { should have_error_message 'Access denied' }
        it { should have_page_title '' }
        it { should have_page_heading 'Developers Connect' }
      end
    end

    describe 'as an author' do

      before do
        @author = Fabricate(:author)
        visit new_user_session_path
        capybara_signin(@author)
      end

      describe 'in the index page' do

        before { visit articles_path }

        it { should have_page_title 'Articles' }
        it { should have_page_heading 'Articles' }
        it { should have_link 'New article', :href => new_article_path }

        describe 'when author has an article in the list' do

          before do
            @article = Fabricate(:article, :author => @author)
            visit articles_path
          end

          it { should have_link 'Edit', :href => edit_article_path(@article) }
          it { should have_link 'Destroy', :method => :delete, :href => article_path(@article) }
        end
      end

      describe 'in the show page' do

        before do
          @article = Fabricate(:article, :author_id => @author.id)
          visit article_path(@article)
        end

        it { should have_page_title @article.title }
        it { should have_page_heading @article.title }
        it { should have_link 'Back to articles' }

        describe 'when author is the one who made the article' do

          it { should have_link 'Edit', :href => edit_article_path(@article) }
          it { should have_link 'Destroy', :method => :delete, :href => article_path(@article) }
        end

        describe 'when author is not the one who made the article' do

          before do
            @other_author = Fabricate(:author)
            click_link 'Sign out'
            click_link 'Sign in'
            capybara_signin(@other_author)
            visit article_path(@article)
          end

          it { should have_link 'Edit', :href => edit_article_path(@article) }
          it { should have_link 'Destroy', :method => :delete, :href => article_path(@article) }
        end
      end

      describe 'on creating articles' do

        before do
          @category = Fabricate(:category)<commit_msg>fix fabricate usage<commit_after>require 'spec_helper'

describe 'Articles pages' do

  subject { page }

  describe 'for anonymous users' do

    describe 'in the index page' do
      before { visit articles_path }

      it { should have_page_title 'Articles' }
      it { should_not have_page_heading 'Post article' }
    end
  end

  describe 'for signed-in users' do

    describe 'as a regular user' do

      before do
        @user = Fabricate(:user)
        visit new_user_session_path
        capybara_signin(@user)
      end

      describe 'in the index page' do

        before { visit articles_path }

        it { should have_page_title 'Articles' }
        it { should have_page_heading 'Articles' }
        it { should_not have_link 'New article' }
        it { should_not have_link 'Edit' }
        it { should_not have_link 'Destroy' }
      end

      describe 'in the show page' do

        before do
          @article = Fabricate(:article)
          visit article_path(@article)
        end

        it { should have_page_title @article.title }
        it { should have_page_heading @article.title }
        it { should have_link 'Back to articles' }
        it { should_not have_link 'Edit' }
        it { should_not have_link 'Destroy' }
      end

      describe 'in the new page' do

        before { visit new_article_path }

        it { should have_error_message 'Access denied' }
        it { should have_page_title '' }
        it { should have_page_heading 'Developers Connect' }
      end

      describe 'in the edit page' do

        before do
          @article = Fabricate(:article)
          visit edit_article_path(@article)
        end

        it { should have_error_message 'Access denied' }
        it { should have_page_title '' }
        it { should have_page_heading 'Developers Connect' }
      end
    end

    describe 'as an author' do

      before do
        @author = Fabricate(:author)
        visit new_user_session_path
        capybara_signin(@author)
      end

      describe 'in the index page' do

        before { visit articles_path }

        it { should have_page_title 'Articles' }
        it { should have_page_heading 'Articles' }
        it { should have_link 'New article', :href => new_article_path }

        describe 'when author has an article in the list' do

          before do
            @article = Fabricate(:article, :author => @author)
            visit articles_path
          end

          it { should have_link 'Edit', :href => edit_article_path(@article) }
          it { should have_link 'Destroy', :method => :delete, :href => article_path(@article) }
        end
      end

      describe 'in the show page' do

        before do
          @article = Fabricate(:article, :author => @author)
          # binding.pry
          visit article_path(@article)
          # save_and_open_page
        end

        it { should have_page_title @article.title }
        it { should have_page_heading @article.title }
        it { should have_link 'Back to articles' }

        describe 'when author is the one who made the article' do

          it { should have_link 'Edit', :href => edit_article_path(@article) }
          it { should have_link 'Destroy', :method => :delete, :href => article_path(@article) }
        end

        describe 'when author is not the one who made the article' do

          before do
            @other_author = Fabricate(:author)
            click_link 'Sign out'
            click_link 'Sign in'
            capybara_signin(@other_author)
            visit article_path(@article)
          end

          it { should_not have_link 'Edit', :href => edit_article_path(@article) }
          it { should_not have_link 'Destroy', :method => :delete, :href => article_path(@article) }
        end
      end

      describe 'on creating articles' do

        before do
          @category = Fabricate(:category)
{'fraction_non_alphanumeric': 0.07873407950598224, 'fraction_numerical': 0.0, 'mean_word_length': 2.1083566573370653, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4902435', 'n_tokens_mistral': 2205, 'n_tokens_neox': 2119, 'n_words': 699}