Skip to content

Instantly share code, notes, and snippets.

@guipdutra
Created January 27, 2014 20:54
Show Gist options
  • Select an option

  • Save guipdutra/8657108 to your computer and use it in GitHub Desktop.

Select an option

Save guipdutra/8657108 to your computer and use it in GitHub Desktop.
# encoding: utf-8
require 'spec_helper'
describe "Filters", :subdomain => 'city1-st' do
let(:city_hall) { city_halls(:main) }
before do
@mapping = lc116_cnae_mapping()
@cnae = cnae()
@lc116 = lc116()
@city = city_halls(:main).city
@taxpayer = taxpayer(:out_of_town)
@cp_taxpayer = taxpayer(:out_of_town_counterparty)
login_with_user(:taxpayer_admin, city_hall, :taxpayer => @taxpayer)
end
it "tells there's no record to show" do
filter = FactoryGirl.create(:agile_filter, :name => 'Divergência por prestador',
:serie => "Underwriting",
:group_by_field => "incidence", :group_by_field_order => "ASC",
:order_by_field => "incidence", :order_by_field_order => "ASC",
:totalize => true
)
visit filter_path(filter)
page.should have_content "Divergência por prestador (0)"
page.should have_content "Nenhum registro encontrado"
end
it "displays a grouped filter without problems" do
FactoryGirl.create(:underwriting, :taxpayer => @taxpayer, :lc116 => @lc116, :number => "123",
:series => nil, :provider => true, :counterparty_taxpayer => @cp_taxpayer)
FactoryGirl.create(:underwriting, :taxpayer => @taxpayer, :lc116 => @lc116, :number => "124",
:series => nil, :provider => true, :counterparty_taxpayer => @cp_taxpayer,
:incidence => (Date.current - 2.month).beginning_of_month)
agile_columns = [
{"name" => "incidence", "position" => "0"},
{"name" => "receiver_combo", "position" => "1"},
{"name" => "doc_info", "position" => "2"},
{"name" => "value_cents", "position" => "3"},
{"name" => "iss_value_cents", "position" => "4"},
{"name" => "divergence_level", "position" => "5"}
]
filter = FactoryGirl.create(:agile_filter, :name => 'Divergência por prestador',
:serie => "Underwriting", :agile_columns_attributes => agile_columns,
:group_by_field => "incidence", :group_by_field_order => "ASC",
:order_by_field => "incidence", :order_by_field_order => "ASC",
:totalize => true
)
visit filter_path(filter)
page.should have_content "Divergência por prestador (2)"
page.should have_content "NF 123"
page.should have_content "NF 124"
page.should have_content "Subtotal"
page.should have_content "Total"
page.should have_content "Incidência"
end
it "lets you clone a filter" do
agile_columns = [
{"name" => "service_date", "position" => "0"},
{"name" => "receiver_combo", "position" => "1"},
{"name" => "doc_info", "position" => "2"},
{"name" => "value_cents", "position" => "3"},
{"name" => "iss_value_cents", "position" => "4"},
{"name" => "divergence_level", "position" => "5"}
]
agile_all_condition = [
{"column" => "divergence_level", "condition" => "NOT NULL", "operator" => "="},
{"column" => "divergence_level", "condition" => "NULL", "operator" => "<>"},
]
agile_any_condition = [
{"column" => "divergence_level", "condition" => "1", "operator" => "<>"},
{"column" => "provider", "condition" => "1", "operator" => "=" }
]
FactoryGirl.create(:agile_filter, :name => 'Divergência por prestador',
:serie => "Underwriting",
:agile_columns_attributes => agile_columns,
:agile_all_conditions_attributes => agile_all_condition,
:agile_any_conditions_attributes => agile_any_condition,
:group_by_field => "provider_combo", :group_by_field_order => "ASC",
:order_by_field => "service_date", :order_by_field_order => "ASC",
:totalize => true,
:user => @taxpayer.default_admin,
:global => true,
:taxpayer_global => true,
:city_hall => city_hall,
:active => true
)
visit filters_path
click_link "Copiar"
page.should have_content "Novo Filtro"
find_field("Nome do Filtro").value.should eq "Divergência por prestador"
fill_in "Nome do Filtro", with: "Novo filtro legal"
click_button "Criar"
page.should have_content "O filtro foi criado com sucesso."
page.should have_content "Novo filtro legal (0)"
end
context "link to the taxpayer xray" do
context "Underwriting" do
before do
login_with_user(user, city_hall)
FactoryGirl.create(:underwriting,
:underwriting_type => "declaration",
:taxpayer => @taxpayer,
:lc116 => @lc116,
:number => "123",
:series => nil,
:provider => true,
:counterparty_taxpayer => @cp_taxpayer)
FactoryGirl.create(:underwriting,
:underwriting_type => "declaration",
:taxpayer => @taxpayer,
:lc116 => @lc116,
:number => "124",
:series => nil,
:provider => true,
:counterparty_taxpayer => @cp_taxpayer,
:incidence => (Date.current - 2.month).beginning_of_month)
filter = FactoryGirl.create(:agile_filter,
:format => "list",
:name => 'Teste link contribuinte',
:serie => "Underwriting")
visit filter_path(filter)
end
context "city_admin" do
let(:user) { :city_admin }
it "shows a link to the taxpayer xray" do
expect(page).to have_selector(:link_or_button, "#{@cp_taxpayer.official_name} - #{Taxpayer.format_cpf_cnpj(@cp_taxpayer.cpf_cnpj)}")
end
end
context "city_agent" do
let(:user) { :city_agent }
it "does not show the link to the taxpayer xray" do
login_with_user(:city_agent, city_hall)
expect(page).not_to have_selector(:link_or_button, "#{@cp_taxpayer.official_name} - #{Taxpayer.format_cpf_cnpj(@cp_taxpayer.cpf_cnpj)}")
end
end
end
context "Nfe" do
before do
login_with_user(user, city_hall)
FactoryGirl.create(:nfe, :provider => @taxpayer, :receiver => @cp_taxpayer, :city_hall => city_hall, :city_id => FactoryGirl.create(:city).id, :cnae => lc116_cnae_mapping().cnae, :lc116 => lc116_cnae_mapping().lc116, :retain_iss => true, :operation_nature => 2)
filter = FactoryGirl.create(:agile_filter,
:format => "list",
:name => 'Teste link contribuinte Nfe',
:serie => "Nfe")
visit filter_path(filter)
end
context "city_admin" do
let(:user) { :city_admin }
it "shows a link to the taxpayer xray" do
expect(page).to have_selector(:link_or_button, "#{@cp_taxpayer.official_name} - #{Taxpayer.format_cpf_cnpj(@cp_taxpayer.cpf_cnpj)}")
end
end
context "city_agent" do
let(:user) { :city_agent }
it "does not shows the link to the taxpayer xray" do
expect(page).not_to have_selector(:link_or_button, "#{@cp_taxpayer.official_name} - #{Taxpayer.format_cpf_cnpj(@cp_taxpayer.cpf_cnpj)}")
end
end
end
def login_with_admin_expectation
expect(page).to have_selector(:link_or_button, "#{@cp_taxpayer.official_name} - #{Taxpayer.format_cpf_cnpj(@cp_taxpayer.cpf_cnpj)}")
end
def login_with_agent_expectation
expect(page).not_to have_selector(:link_or_button, "#{@cp_taxpayer.official_name} - #{Taxpayer.format_cpf_cnpj(@cp_taxpayer.cpf_cnpj)}")
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment