mysociety/alaveteli

View on GitHub
spec/integration/alaveteli_pro/add_remove_embargo_spec.rb

Summary

Maintainability
A
1 hr
Test Coverage
# -*- encoding : utf-8 -*-
require 'spec_helper'
require File.expand_path(File.dirname(__FILE__) + '/../alaveteli_dsl')

describe 'Adding/removing embargoes from requests' do

  let(:pro_user) { FactoryGirl.create(:pro_user) }
  let(:user) { FactoryGirl.create(:user) }
  let!(:user_session) { login(user) }

  describe "adding an embargo to a request" do

    let!(:info_request) do
      FactoryGirl.create(:info_request, user: pro_user,
                                        title: 'My awesome request')
    end

    it 'removes the request from the search results' do
      TestAfterCommit.with_commits(true) do
        update_xapian_index

        using_session(user_session) do
          visit frontpage_path
          fill_in "navigation_search_button", :with => 'awesome'
          click_button "Search"
          expect(page).to have_content(info_request.title)
        end
      end

      # add the embargo
      FactoryGirl.create(:embargo, info_request: info_request)

      TestAfterCommit.with_commits(true) do
        update_xapian_index

        using_session(user_session) do
          visit frontpage_path
          fill_in "navigation_search_button", :with => 'awesome'
          click_button "Search"
          expect(page).not_to have_content(info_request.title)
        end
      end
    end

  end

  describe 'removing an embargo from a request' do

    let!(:info_request) do
      request = FactoryGirl.create(:info_request, user: pro_user,
                                                  title: 'My embargoed request')
      FactoryGirl.create(:embargo, info_request: request)
      request
    end

    it 'adds the request to the search results' do
      TestAfterCommit.with_commits(true) do
        update_xapian_index

        using_session(user_session) do
          visit frontpage_path
          fill_in "navigation_search_button", :with => 'embargoed'
          click_button "Search"
          expect(page).not_to have_content(info_request.title)
        end
      end

      # destroy the embargo
      info_request.embargo.destroy

      TestAfterCommit.with_commits(true) do
        update_xapian_index

        using_session(user_session) do
          visit frontpage_path
          fill_in "navigation_search_button", :with => 'embargoed'
          click_button "Search"
          expect(page).to have_content(info_request.title)
        end
      end
    end

  end
end