**Ruby 1.9.3, Rails 2.13.0, WebMock 1.17.4**
I am writing tests for a company app. The controller in question displays a table of a customer's placed calls, and allows for sort/filter options.
1. As a call is placed, its data joins an xml file, **created by an external API, called _Recorder_**
2. The _RecordingsController_ takes the xml file, and parses it into a hash.
3. When you visit the associated path, you see the results of the hash -- a table of placed calls, their attributes, and parameters for sort/filter.
Here is my spec so far.
require 'spec_helper'
include Helpers
feature 'Exercise recordings controller' do
include_context "shared admin context"
scenario 'show index page with empty xml' do
canned_xml = File.open("spec/support/assets/canned_response.xml").read
stub_request(:get, /localhost\:3000/).
with(headers: {'Accept'=>'*/*', 'User-Agent'=>'Ruby'}).
to_return(status: 200, body: canned_xml, headers: {})
uri = URI.parse("http://localhost:3000/recorder/index")
visit recorded_calls_path
page.save_and_open_page
expect(title).to eq("Recorded Calls")
end
end
And here is the RecordingsController
class RecordingsController < ApplicationController
# before_filter options
def index
test_session_id = request.session_options[:id]
#Make request to recording app for xml of files
uri = URI.parse("http://#{Rails.application.config.recorder_server}:#{Rails.application.config.recorder_server_port}/recorder/index")
http = Net::HTTP.new(uri.host, uri.port)
xml_request = Net::HTTP::Post.new(uri.request_uri)
xml_request_data = Hash.new
# ... sorting params
xml_request_data[:shared_session_id] = request.session_options[:id]
xml_request.set_form_data(xml_request_data)
response = http.request(xml_request)
if response.class == Net::HTTPOK
@recordings_xml = XmlSimple.xml_in(response.body)
@recordings_sorted = @recordings_xml["Recording"].sort { |a,b| Time.parse("#{a["date"]} #{a["time"]}") <=> Time.parse("#{b["date"]} #{b["time"]}") } unless @recordings_xml["Recording"].nil?
else @recordings_xml = Hash.new
end
end
# ... other defs
end
Any and all advice is much appreciated. Thank you.