Create a gist now

Instantly share code, notes, and snippets.

getting params into my model test
**************
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