<commit_before># encoding: utf-8
require "spec_helper"

def new_window_should_have_content(content)
  new_window = page.driver.browser.window_handles.last
  page.within_window new_window do
    page.should have_content(content)
  end
end

module Refinery
  module Admin
    describe "Pages" do
      refinery_login_with :refinery_user

      context "when no pages" do
        it "invites to create one" do
          visit refinery.admin_pages_path
          page.should have_content(%q{There are no pages yet. Click "Add new page" to add your first page.})
        end
      end

      describe "action links" do
        it "shows add new page link" do
          visit refinery.admin_pages_path

          within "#actions" do
            page.should have_content("Add new page")
            page.should have_selector("a[href='/refinery/pages/new']")
          end
        end

        context "when no pages" do
          it "doesn't show reorder pages link" do
            visit refinery.admin_pages_path

            within "#actions" do
              page.should have_no_content("Reorder pages")
              page.should have_no_selector("a[href='/refinery/pages']")
            end
          end
        end

        context "when some pages exist" do
          before(:each) { 2.times { FactoryGirl.create(:page) } }

          it "shows reorder pages link" do
            visit refinery.admin_pages_path

            within "#actions" do
              page.should have_content("Reorder pages")
              page.should have_selector("a[href='/refinery/pages']")
            end
          end
        end

        context "when sub pages exist" do
          let(:company) { FactoryGirl.create(:page, :title => "Our Company") }
          let(:team) { FactoryGirl.create(:page, :parent => company, :title => 'Our Team') }
          let(:locations) { FactoryGirl.create(:page, :parent => company, :title => 'Our Locations')}
          let(:location) { FactoryGirl.create(:page, :parent => locations, :title => 'New York') }

          context "with auto expand option turned off" do
            before do
              Refinery::Pages.auto_expand_admin_tree = false

              # Pre load pages
              location
              team

              visit refinery.admin_pages_path
            end

            it "show parent page" do

              page.should have_content(company.title)
            end

            it "doesn't show children" do
              page.should_not have_content(team.title)
              page.should_not have_content(locations.title)
            end

            it "expands children", :js => true do
              find(".toggle").click

              page.should have_content(team.title)
              page.should have_content(locations.title)
            end

            it "expands children when nested mutliple levels deep", :js => true do
              find("#page_#{company.id} .toggle").click
              find("#page_#{locations.id} .toggle").click

              page.should have_content("New York")
            end
          end

          context "with auto expand option turned on" do
            before do
              Refinery::Pages.auto_expand_admin_tree = true

              # Pre load pages
              location
              team

              visit refinery.admin_pages_path
            end

            it "shows children" do
              page.should have_content(team.title)
              page.should have_content(locations.title)
            end
          end
        end
      end

      describe "new/create" do
        it "allows to create page" do
          visit refinery.admin_pages_path

          click_link "Add new page"

          fill_in "Title", :with => "My first page"
          click_button "Save"

          page.should have_content("'My first page' was successfully added.")

          page.body.should =~ /Remove this page forever/
          page.body.should =~ /Edit this page/
          page.body.should =~ %r{/refinery/pages/my-first-page/edit}
          page.body.should =~ /Add a new child page/<commit_msg>Use let! to create pages right away so that we don't have to create them manually in before block. Stub config instead of setting it directly.<commit_after># encoding: utf-8
require "spec_helper"

def new_window_should_have_content(content)
  new_window = page.driver.browser.window_handles.last
  page.within_window new_window do
    page.should have_content(content)
  end
end

module Refinery
  module Admin
    describe "Pages" do
      refinery_login_with :refinery_user

      context "when no pages" do
        it "invites to create one" do
          visit refinery.admin_pages_path
          page.should have_content(%q{There are no pages yet. Click "Add new page" to add your first page.})
        end
      end

      describe "action links" do
        it "shows add new page link" do
          visit refinery.admin_pages_path

          within "#actions" do
            page.should have_content("Add new page")
            page.should have_selector("a[href='/refinery/pages/new']")
          end
        end

        context "when no pages" do
          it "doesn't show reorder pages link" do
            visit refinery.admin_pages_path

            within "#actions" do
              page.should have_no_content("Reorder pages")
              page.should have_no_selector("a[href='/refinery/pages']")
            end
          end
        end

        context "when some pages exist" do
          before(:each) { 2.times { FactoryGirl.create(:page) } }

          it "shows reorder pages link" do
            visit refinery.admin_pages_path

            within "#actions" do
              page.should have_content("Reorder pages")
              page.should have_selector("a[href='/refinery/pages']")
            end
          end
        end

        context "when sub pages exist" do
          let!(:company) { FactoryGirl.create(:page, :title => 'Our Company') }
          let!(:team) { FactoryGirl.create(:page, :parent => company, :title => 'Our Team') }
          let!(:locations) { FactoryGirl.create(:page, :parent => company, :title => 'Our Locations')}
          let!(:location) { FactoryGirl.create(:page, :parent => locations, :title => 'New York') }

          context "with auto expand option turned off" do
            before do
              Refinery::Pages.stub(:auto_expand_admin_tree).and_return(false)

              visit refinery.admin_pages_path
            end

            it "show parent page" do

              page.should have_content(company.title)
            end

            it "doesn't show children" do
              page.should_not have_content(team.title)
              page.should_not have_content(locations.title)
            end

            it "expands children", :js => true do
              find("#page_#{company.id} .toggle").click

              page.should have_content(team.title)
              page.should have_content(locations.title)
            end

            it "expands children when nested mutliple levels deep", :js => true do
              find("#page_#{company.id} .toggle").click
              find("#page_#{locations.id} .toggle").click

              page.should have_content("New York")
            end
          end

          context "with auto expand option turned on" do
            before do
              Refinery::Pages.stub(:auto_expand_admin_tree).and_return(true)

              visit refinery.admin_pages_path
            end

            it "shows children" do
              page.should have_content(team.title)
              page.should have_content(locations.title)
            end
          end
        end
      end

      describe "new/create" do
        it "allows to create page" do
          visit refinery.admin_pages_path

          click_link "Add new page"

          fill_in "Title", :with => "My first page"
          click_button "Save"

          page.should have_content("'My first page' was successfully added.")

          page.body.should =~ /Remove this page forever/
          page.body.should =~ /Edit this page/
          page.body.should =~ %r{/refinery/pages/my-first-page/edit}
          page.body.should =~ /Add a new child page/
{'fraction_non_alphanumeric': 0.08815326785497757, 'fraction_numerical': 0.0004850248575239481, 'mean_word_length': 1.8539792387543252, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 23, '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': '3624527', 'n_tokens_mistral': 2239, 'n_tokens_neox': 2156, 'n_words': 639}