I am trying to test a "Post create" action with Rspec. The code is as follows:
def valid_attributes
{
:zone => Flymgr::Zone.new(:countries => Flymgr::ZoneCountry.first,
:name => 'USA',
:description => 'USA Flight',
:zipcodes => ''),
:price => '100.00',
:class => 'first',
}
end
def valid_session
{}
end
before(:each) do
@request.env["devise.mapping"] = Devise.mappings[:admin]
admin = FactoryGirl.create(:admin)
sign_in admin
end
describe "POST create" do
describe "with valid params" do
it "creates a new Flymgr::Rule" do
expect {
post :create, {:Flymgr_rule => valid_attributes}
}.to change(Flymgr::Rule, :count).by(1)
end
One of the required attributes for the form is a 'zone', this is a dropdown box and the options for the dropdown are created with a different form. I do not know how to create an form entry using Rspec. As you can see, I have tried to call a method from a different controller Flymgr::Zone.new
. I don't think this is working and it is breaking my test.
Can anyone advise on the best way to do this? Perhaps I should be using FactoryGirl to create a zone and rule entry?