Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

getting params into my model test

View rspec model test
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
**************
Inbound params from a third party
**************
# params => {"unit_id"=>"4eb2204eed964930f4000049", "final_outputs"=>[{"birth_day"=>[""], "birth_month"=>[""], "birth_year"=>["1913"], "death_day"=>[""], "death_month"=>[""], "death_year"=>["1999"], "first_name"=>["Gladys"], "gender"=>["female"], "max_no"=>"", "middle_name"=>["Opal"], "military_service"=>[""], "not_readable"=>"", "number"=>"", "rotated"=>"", "suffix"=>[""], "surname"=>["Abbott"], "veteran"=>["no"], "eulogy"=>["Beloved Mother and Wife"], "id"=>"4eb36ff117c0dd5bd5000003"}], "meta_data"=>"16585"}
 
*************
Controller -
*************
def create
@record = Record.find(params[:meta_data])
@record.save_cf_data(params)
render :nothing => true
end
**********
Model:
**********
def save_cf_data(params)
result = params[:final_outputs].first
self.surname = result['surname'].first.upcase()
self.save
end
end
************
Spec:
************
describe Record do
describe '#save_cf_data' do
before :each do
@record = Record.new
end
 
it "should have a surname" do
result = {"final_outputs"=>["surname"=>["hagan"]]}
@record.save_cf_data(result)
surname = @record.surname
surname.should eql("HAGAN")
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.