Below is my active admin resource file and the rspec feature.
When I run the rspec...it fails Failure/Error: select "Full-Year", from: "From Finance Month" Capybara::ElementNotFound: Unable to find option "Full-Year" Can anyone please help ???
Resource file: ActiveAdmin.register PamClient::RevenueVarianceMapping, as: "RevenueVarianceMapping" do menu parent: "FINANCE" config.comments = false
filter :from_year_id, as: :select, collection: PamClient::CalendarYear.all, label: 'From Year'
filter :from_finance_month filter :from_model_id_eq, as: :select, label: 'From Model', collection: proc { PamClient::RevenueVarianceMapping.joins(:from_finance_model).map { |a| [ a.from_finance_model.finance_model_name, a.from_finance_model.finance_model_id ] }.uniq }
filter :lrp_from_year, label: 'Lrp From Year'
filter :to_year_id, as: :select, collection: PamClient::CalendarYear.all, label: 'To Year' filter :to_finance_month filter :to_model_id_eq, as: :select, label: 'To Model', collection: proc { PamClient::RevenueVarianceMapping.joins(:to_finance_model).map { |a| [ a.to_finance_model.finance_model_name, a.to_finance_model.finance_model_id ] }.uniq }
filter :lrp_to_year, label: 'Lrp To Year' filter :associated_month filter :associated_year_id, as: :select, collection: PamClient::CalendarYear.all, label: 'Associated Year'
actions :all, except: [:destroy, :show]
permit_params :from_year_id, :from_finance_month_id, :from_model_id, :to_year_id, :to_finance_month_id, :to_model_id, :associated_month_id, :associated_year_id,:lrp_from_year,:lrp_to_year
controller do def create create! do |success, failure| success.html { redirect_to admin_revenue_variance_mappings_path } end end end
collection_action :dynamic_select, :method => :post do full_year_model_types = PamClient::FinanceModelType.where(PamClient::FinanceModelType.arel_table[:finance_model_type_name].not_eq('CURRENT YEAR - MONTHLY')) full_year_models = PamClient::FinanceModel.order(:display_order).where(finance_model_type_id: full_year_model_types.map(&:finance_model_type_id)) finance_model_ids = full_year_models.map(&:finance_model_id) if finance_model_ids.include? (params[:pam_client_revenue_variance_mapping_to_model_id].to_i) models = [PamClient::FinanceMonth.yearly_month] else if finance_model_ids.include? (params[:pam_client_revenue_variance_mapping_from_model_id].to_i) models = [PamClient::FinanceMonth.yearly_month] else models = PamClient::FinanceMonth.twelve_months end end render :text => view_context.options_from_collection_for_select(models, :id, :finance_month_name) end
member_action :change_neighbourhoods, :method => :get do
end
member_action :set_default_values, :method => :get do PamClient::FinanceVarianceHeader.set_default params[:id] redirect_to admin_revenue_variance_mappings_path end
index do column :from_year do |rvm| rvm.from_year.calendar_year end column :from_finance_month column "From Model", :from_finance_model column "Lrp From Year", :lrp_from_year
column :to_year do |rvm|
rvm.to_year.calendar_year
end
column :to_finance_month
column "To Model", :to_finance_model
column "Lrp To Year", :lrp_to_year
column :associated_month
column :associated_year do |rvm|
rvm.associated_year.calendar_year
end
actions defaults: true do |calendar_year|
link_to('Set Default Values', set_default_values_admin_revenue_variance_mapping_path(calendar_year))
end
end
form do |f| f.inputs do f.input :from_year, collection: PamClient::CalendarYear.all.map { |cy| [cy.calendar_year, cy.calendar_year_id] } f.input :from_model_id, as: :select, collection: PamClient::FinanceModel.all, label: 'From Finance Model', input_html: { onchange: remote_get('pam_client_revenue_variance_mapping_from_model_id', 'pam_client_revenue_variance_mapping_from_finance_month_id')}
f.input :lrp_from_year, as: :select, collection: ["LRP 1st YEAR","LRP 2nd YEAR"], input_html: {disabled: true }, label: 'Lrp From Year'
f.input :from_finance_month_id, as: :select, collection: PamClient::FinanceMonth.for_revenue_variance_mapping(f.object.from_model_id), label: 'From Finance Month'
f.input :to_year, collection: PamClient::CalendarYear.all.map { |cy| [cy.calendar_year, cy.calendar_year_id] }
f.input :to_model_id, as: :select, collection: PamClient::FinanceModel.all, label: 'To Finance Model', input_html: {
onchange: remote_get('pam_client_revenue_variance_mapping_to_model_id', 'pam_client_revenue_variance_mapping_to_finance_month_id')}
f.input :lrp_to_year, as: :select, collection: ["LRP 1st YEAR","LRP 2nd YEAR"], input_html: { disabled: true}, label: 'Lrp To Year'
f.input :to_finance_month_id, as: :select, collection: PamClient::FinanceMonth.for_revenue_variance_mapping(f.object.to_model_id), label: 'To Finance Month'
f.input :associated_month, collection: PamClient::FinanceMonth.twelve_months.map { |fm| [fm.finance_month_name, fm.finance_month_id] }
f.input :associated_year, collection: PamClient::CalendarYear.all.map { |cy| [cy.calendar_year, cy.calendar_year_id] }
end
f.actions
end end
Feature spec:
require 'spec_helper'
feature 'Manage RevenueVarianceMapping' do fixtures :all
let!(:from_finance_model1) { FactoryGirl.create(:finance_model, name: 'Budget') } let!(:from_finance_month1) { FactoryGirl.create(:finance_month, finance_month_name: 'Full-Year') }
scenario "managing revenue variance mapping" do Given "I am logged in as an admin" When "I visit the admin page" And "I click on the revenue variance mappings page" And "I click on new revenue variance mapping" Then "I should see the new revenue variance mapping in the index" end
def i_am_logged_in_as_an_admin user = app_user(:fedyna_the_superadmin) user.roles << FactoryGirl.create(:role, :admin) login_as user end
def i_visit_the_admin_page visit admin_root_path end
def i_click_on_the_revenue_variance_mappings_page within_admin_navbar do click_on "Revenue Variance Mappings" end end
def i_click_on_new_revenue_variance_mapping click_on "New Revenue Variance Mapping" select "2012", from: "From year" select "Budget", from: "From Finance Model" select "Full-Year", from: "From Finance Month" select "2013", from: "To year" select "fmodel2", from: "To Finance Model" select "fmonth2", from: "To Finance Month" select "May", from: "Associated month" select "2013", from: "Associated year" click_on "Create Revenue variance mapping" end
def i_should_see_the_new_revenue_variance_mapping_in_the_index txt_ary = page.all('table').map(&:text) expect(txt_ary).to include( a_string_matching(/2012/), a_string_matching(/model1/), a_string_matching(/Full-Year/) )
end end
Aucun commentaire:
Enregistrer un commentaire