<commit_before>require_relative "../spec_helper"

describe "Articles" do
  let(:user) do
    TestUser.new.tap do |user|
      user.action_framework = self
    end
  end

  let(:background) { ArticleBackground.new }

  context "reader at" do
    let(:alice) { user.act_as :ArticleReader }

    context "article listing" do
      before(:each) do
        @oor = background.publish_article :oor_article
        @js  = background.publish_article :js_article

        alice.click 'articles'
      end

      it "should see existing articles" do
        [@oor, @js].each do |article|
          alice.see link: article.title
          alice.see article.sumary
        end
      end

      it "able to open article page" do
        alice.click @oor.title

        alice.see @oor.title,
                  @oor.sumary,
                  @oor.content
      end
    end
  end

  context "admin at" do
    let(:alex) { user.act_as :ArticleEditor }

    context "article listing" do
      before(:each) do
        @oor       = background.publish_article :oor_article
        @invisible = background.publish_article :invisible_article

        alex.click 'articles'
      end

      it "should see regular and invisible articles" do
        [@oor, @invisible].each do |article|
          alex.see link: article.title
          alex.see article.sumary
        end
      end

      it "able to open article view page" do
        alex.click @oor.title

        alex.see  @oor.title,
                  @oor.sumary,
                  @oor.content

        alex.see 'edit'
      end

      it "able to open article edit page" do
        alex.click @oor.title,
                   'edit' # TODO Click edit near title...

        # check presence on a page by "be at page"
        current_path.should == background.edit_article_path(@oor)
      end
    end

    describe "edit article page" do
      it "should see article fields inside inputs tags" do
        within 'input' do alex.see @oor.title end
        within 'input' do alex.see @oor.sumary end
        within 'input' do alex.see @oor.content end
      end

      it "changes title" do
        alex.open_edit_article_page_for @oor

        fill_in "New title for OOR book" => :title
        click 'save'

        alex.see 'updated successfully'

        alex.open_article_listing
        alex.see "New title for OOR book"
      end

      it "changes summary" do
        alex.open_edit_article_page_for @oor

        fill_in "New summary for OOR book" => :summary
        click 'save'

        alex.see 'updated successfully'

        alex.open_article_listing
        alex.see "New summary for OOR book"
      end

      it "changes content" do
        alex.open_edit_article_page_for @oor

        fill_in "New content for OOR book" => :content
        click 'save'

        alex.see 'updated successfully'

        alex.open_article_listing
        alex.see "New content for OOR book"
      end
    end
  end

end<commit_msg>Pending intergation examples<commit_after>require_relative "../spec_helper"

describe "Articles" do
  let(:user) do
    TestUser.new.tap do |user|
      user.action_framework = self
    end
  end

  let(:background) { ArticleBackground.new }

  context "reader at" do
    let(:alice) { user.act_as :ArticleReader }

    context "article listing" do
      before(:each) do
        @oor = background.publish_article :oor_article
        @js  = background.publish_article :js_article

        alice.click 'articles'
      end

      pending "should see existing articles" do
        [@oor, @js].each do |article|
          alice.see link: article.title
          alice.see article.sumary
        end
      end

      pending "able to open article page" do
        alice.click @oor.title

        alice.see @oor.title,
                  @oor.sumary,
                  @oor.content
      end
    end
  end

  context "admin at" do
    let(:alex) { user.act_as :ArticleEditor }

    context "article listing" do
      before(:each) do
        @oor       = background.publish_article :oor_article
        @invisible = background.publish_article :invisible_article

        alex.click 'articles'
      end

      pending "should see regular and invisible articles" do
        [@oor, @invisible].each do |article|
          alex.see link: article.title
          alex.see article.sumary
        end
      end

      pending "able to open article view page" do
        alex.click @oor.title

        alex.see  @oor.title,
                  @oor.sumary,
                  @oor.content

        alex.see 'edit'
      end

      pending "able to open article edit page" do
        alex.click @oor.title,
                   'edit' # TODO Click edit near title...

        # check presence on a page by "be at page"
        current_path.should == background.edit_article_path(@oor)
      end
    end

    describe "edit article page" do
      pending "should see article fields inside inputs tags" do
        within 'input' do alex.see @oor.title end
        within 'input' do alex.see @oor.sumary end
        within 'input' do alex.see @oor.content end
      end

      pending "changes title" do
        alex.open_edit_article_page_for @oor

        fill_in "New title for OOR book" => :title
        click 'save'

        alex.see 'updated successfully'

        alex.open_article_listing
        alex.see "New title for OOR book"
      end

      pending "changes summary" do
        alex.open_edit_article_page_for @oor

        fill_in "New summary for OOR book" => :summary
        click 'save'

        alex.see 'updated successfully'

        alex.open_article_listing
        alex.see "New summary for OOR book"
      end

      pending "changes content" do
        alex.open_edit_article_page_for @oor

        fill_in "New content for OOR book" => :content
        click 'save'

        alex.see 'updated successfully'

        alex.open_article_listing
        alex.see "New content for OOR book"
      end
    end
  end

end
{'fraction_non_alphanumeric': 0.07718008686936184, 'fraction_numerical': 0.0, 'mean_word_length': 1.9162201656113005, 'pattern_counts': {'":': 0, '<': 3, '<?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': '5429568', 'n_tokens_mistral': 1809, 'n_tokens_neox': 1679, 'n_words': 545}