ruby - Writing a Rails Integration test for a search controller -
i testing app. have feature can search registered members first name, last name, city, state, etc... think integration test work better controller test, having hard time figuring out start. here code controller:
class msearchescontroller < applicationcontroller def new @msearch = msearch.new @first_name = user.uniq.pluck(:first_name) @last_name = user.uniq.pluck(:last_name) @state = user.uniq.pluck(:state) @cities = user.uniq.pluck(:city) end def create @msearch = msearch.create(msearch_params) redirect_to @msearch end def show @users = user.all @msearch = msearch.find(params[:id]) @first_name = user.uniq.pluck(:first_name) @last_name = user.uniq.pluck(:last_name) @states = user.uniq.pluck(:state) @cities = user.uniq.pluck(:city) end def update @msearch = msearch.new end private def msearch_params params.require(:msearch).permit(:first_name, :last_name, :state, :city, :agency) end end any in getting me started appreciated!
i agree better tested @ acceptance level controller level since there's nothing assert on in controller test verify it's doing it's supposed to. controller delegates work business objects , views. need exercise of them verify it's doing job correctly. controller unit tests redundant reason.
i use following test functionality @ acceptance level (assumes using capybara , factorygirl).
feature "user search", type: :feature scenario "search user first name" @frodo = create(:user, first_name: "frodo") @sam = create(:user, first_name: "sam") visit new_msearch_path fill_in "user_first_name", with: "frodo" click_button "search" expect(page).to have_content "frodo" expect(page).to_not have_content "sam" end # ... similar tests cover each field / search case ... end is msearch class gem? or did implement yourself? if it's own class, might want test @ unit level can exercise more complex edge cases without overhead of full stack.
Comments
Post a Comment