Last active
August 29, 2015 13:56
-
-
Save cored/9079185 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class JobsController < ApplicationController | |
def latest_active | |
@jobs = Jobo::Jobs::ListGroupedByCategories.list Job | |
end | |
def new | |
@job = Job.new | |
end | |
def create | |
Jobo::Jobs::Creator.call Job, params['job'] | |
redirect_to :root | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
JobsController POST /create creates a new job | |
Failure/Error: expect(job_creator).to receive(:call).with(Job, job_attrs) | |
(Double :job_creator_service).call(Job(id: integer, location: string, position: string, company: string, created_at: datetime, updated_at: datetime, category_id: integer, type: integer, url: string, description: text, how_to_apply: string, public: boolean, email: string), {"id"=>nil, "location"=>"Delaware", "position"=>"Dynamic Research Officer", "company"=>"Abshire Inc", "created_at"=>nil, "updated_at"=>nil, "category_id"=>79, "type"=>nil, "url"=>nil, "description"=>nil, "how_to_apply"=>nil, "public"=>nil, "email"=>nil}) | |
expected: 1 time with arguments: (Job(id: integer, location: string, position: string, company: string, created_at: datetime, updated_at: datetime, category_id: integer, type: integer, url: string, description: text, how_to_apply: string, public: boolean, email: string), {"id"=>nil, "location"=>"Delaware", "position"=>"Dynamic Research Officer", "company"=>"Abshire Inc", "created_at"=>nil, "updated_at"=>nil, "category_id"=>79, "type"=>nil, "url"=>nil, "description"=>nil, "how_to_apply"=>nil, "public"=>nil, "email"=>nil}) | |
received: 0 times with arguments: (Job(id: integer, location: string, position: string, company: string, created_at: datetime, updated_at: datetime, category_id: integer, type: integer, url: string, description: text, how_to_apply: string, public: boolean, email: string), {"id"=>nil, "location"=>"Delaware", "position"=>"Dynamic Research Officer", "company"=>"Abshire Inc", "created_at"=>nil, "updated_at"=>nil, "category_id"=>79, "type"=>nil, "url"=>nil, "description"=>nil, "how_to_apply"=>nil, "public"=>nil, "email"=>nil}) | |
# ./spec/controllers/jobs_controller_spec.rb:22:in `block (3 levels) in <top (required)>' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'spec_helper' | |
describe JobsController do | |
let(:job) { double :job } | |
context 'GET /new' do | |
it 'assigns a new job' do | |
allow(Job).to receive(:new).and_return(job) | |
get :new | |
expect(assigns(:job)).to eql(job) | |
end | |
end | |
context 'POST /create' do | |
let(:job_attrs) { build(:job).attributes } | |
let(:job_creator) { double :job_creator_service } | |
it 'creates a new job' do | |
post :create, job: job_attrs | |
stub_const('Jobo::Jobs::Creator', job_creator) | |
expect(job_creator).to receive(:call).with(Job, job_attrs) | |
end | |
it 'redirects to the list of jobs' do | |
post :create, job: job_attrs | |
allow(job).to receive(:call).and_return(true) | |
expect(page).to redirect_to :root | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment