spec/report_spec.rb in cic-1.0.0 vs spec/report_spec.rb in cic-1.0.1
- old
+ new
@@ -1,34 +1,47 @@
require 'spec_helper'
require 'cic/report'
require 'cic/errors'
require 'helper'
+require 'active_support/core_ext/object/to_query'
describe Cic::Report do
URL = "http://api.nl.cic.mx/0/nl/reports.json"
before(:each) do
- @attr = {"ticket"=>"#7LVB", "content"=>"*ACCIDENTE* En Carretera a Laredo y Jos\u00E9 Clemente Orozco ESC #mtyfollow 11:32 via @escuadronvial", "state"=>"read", "created_at"=>"2013-02-20T11:33:37-06:00", "updated_at"=>"2013-02-20T11:35:20-06:00", "lat"=>"25.79174804389648", "lng"=>"-100.28132557868958", "is_public"=>true, "votes"=>0, "stars"=>0.0, "address_detail"=>{"formatted_address"=>"Jose Clemente Orozco, Sin Nombre de Colonia 17, General Escobedo, NL, M\u00E9xico", "zipcode"=>nil, "county"=>{"long_name"=>"General Escobedo", "short_name"=>"Gral Escobedo"}, "state"=>{"long_name"=>"Nuevo Le\u00F3n", "short_name"=>"NL"}, "neighborhood"=>{"long_name"=>"Sin Nombre de Colonia 17", "short_name"=>"Sin Nombre de Col 17"}}, "group"=>"Vialidad y Transito (SS)", "categories"=>["ACCIDENTE"]}
+ @attr = { "content" => "*ACCIDENTE* En Carretera a Laredo y Jos\u00E9 Clemente Orozco ESC #mtyfollow 11:32 via @escuadronvial", "state" => "read", "created_at" => "2013-02-20T11:33:37-06:00", "updated_at" => "2013-02-20T11:35:20-06:00", "lat" => "25.79174804389648", "lng" => "-100.28132557868958", "is_public" => true, "votes" => 0, "stars" => 0.0, "address_detail" => {
+ "formatted_address" => "Jose Clemente Orozco, Sin Nombre de Colonia 17, General Escobedo, NL, M\u00E9xico", "zipcode" => nil, "county" => {
+ "long_name" => "General Escobedo", "short_name" => "Gral Escobedo"
+ }, "state" => {
+ "long_name" => "Nuevo Le\u00F3n", "short_name" => "NL"
+ }, "neighborhood" => {
+ "long_name" => "Sin Nombre de Colonia 17", "short_name" => "Sin Nombre de Col 17"
+ }
+ }, "group" => "Vialidad y Transito (SS)", "categories" => ["ACCIDENTE"]
+ }
end
subject { Cic::Report.new(@attr) }
let(:report) { Cic::Report.new(@attr) }
it { should respond_to(:attributes) }
it { should respond_to(:raw_attributes) }
describe '#find' do
+ before(:each) do
+ @find_attr = @attr.merge({ "ticket" => "#A2S3" })
+ end
context 'when response is success' do
it 'returns the record specified by the ticket id' do
- mock_request(URL, { reports: [@attr] })
- Cic::Report.find(@attr['ticket']).ticket.should eql @attr['ticket']
+ mock_request(URL, { reports: [@find_attr] })
+ Cic::Report.find(@find_attr['ticket']).ticket.should eql @find_attr['ticket']
end
it 'returns nil when no record found' do
- mock_request(URL, { reports: [@attr] })
+ mock_request(URL, { reports: [@find_attr] })
Cic::Report.find('#1234').should be_nil
end
end
context 'when response fails' do
@@ -99,21 +112,25 @@
end
describe '#save' do
before(:each) do
@params = {
- content: 'Prueba Kuri jalo',
- address: 'cataluna 206',
- origin: 'mailto:jsmith@example.com',
- return_path: 'mailto:jsmith@example.com',
- lat: '25.67316978132684',
- lng: '-100.35339117050171',
- address: 'cataluna 206',
- assets: 'http://icalialabs.com/img/logo.png'
+ content: 'Lorem'
}
+ @report = Cic::Report.new(@attr)
+ stub_request(:post, "http://api.nl.cic.mx/0/nl/reports.json").
+ with(:body => "content=*ACCIDENTE*%20En%20Carretera%20a%20Laredo%20y%20Jos%C3%A9%20Clemente%20Orozco%20ESC%20%23mtyfollow%2011%3A32%20via%20%40escuadronvial&state=read&created_at=2013-02-20T11%3A33%3A37-06%3A00&updated_at=2013-02-20T11%3A35%3A20-06%3A00&lat=25.79174804389648&lng=-100.28132557868958&is_public=true&votes=0&stars=0.0&address_detail[formatted_address]=Jose%20Clemente%20Orozco%2C%20Sin%20Nombre%20de%20Colonia%2017%2C%20General%20Escobedo%2C%20NL%2C%20M%C3%A9xico&address_detail[zipcode]=&address_detail[county][long_name]=General%20Escobedo&address_detail[county][short_name]=Gral%20Escobedo&address_detail[state][long_name]=Nuevo%20Le%C3%B3n&address_detail[state][short_name]=NL&address_detail[neighborhood][long_name]=Sin%20Nombre%20de%20Colonia%2017&address_detail[neighborhood][short_name]=Sin%20Nombre%20de%20Col%2017&group=Vialidad%20y%20Transito%20(SS)&categories[]=ACCIDENTE",
+ :headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Ruby'}).
+ to_return(:status => 200, :body => {reports: { ticket: "#123" }}.to_json, :headers => {"Content-Type" => 'application/json'})
end
+
it 'returns true if report was saved successfully' do
- report = Cic::Report.new(@params)
- report.save.should be_true
+ expect(report.save).to eql(true)
end
+
+ it 'returns a ticket number on the response' do
+ expect{ @report.save }.to change{ @report.ticket_id }.from(nil).to("#123")
+ end
+
+
end
end