Permalink
Browse files

updated client to work over http with json instead of accessing the l…

…ocal rails environment directly
  • Loading branch information...
1 parent 3eef944 commit 4a3b8709e999291c4f2c42041f2a9af7514d3d77 Frans Krojegård committed Apr 20, 2012
Showing with 25 additions and 6 deletions.
  1. +20 −5 client.rb
  2. +5 −1 spec/requests/companies_spec.rb
View
@@ -7,14 +7,29 @@
ENV['RAILS_ENV'] ||= 'development'
require File.expand_path(File.dirname(__FILE__) + "/config/environment")
+require 'open-uri'
+
+protocol = 'http'
+host = 'localhost'
+port = 3000
+path = '/companies.json'
+parameter = 'query'
+
ARGV.each do |a|
puts "Söker efter: #{a}"
- companies = AllaBolagSearcher.search(a)
- companies.each do |c|
- puts "#{c.name} - #{c.identification_no}"
- end
- if companies.empty?
+ puts ""
+
+ url = "#{protocol}://#{host}:#{port}#{path}?#{parameter}=#{a}"
+ content = open(url)
+ companies = JSON.parse(content.string)
+
+ if companies.any?
+ companies.each do |c|
+ puts "#{c["name"]} - #{c["identification_no"]}"
+ end
+ else
puts "Inga resultat."
end
+
puts ""
end
@@ -22,9 +22,13 @@ def valid_attributes
end
describe "GET /companies.xml" do
- it "responds with XML" do
+ require 'open-uri'
+ it "responds with XML" do
visit companies_path(format: :xml, query: @company.name)
page.response_headers["Content-Type"].should eq("application/xml; charset=utf-8")
+ # Fuck this. Parsing XML sucks.
+ page.should have_content(@company.name)
+ page.should have_content(@company.identification_no)
end
end

0 comments on commit 4a3b870

Please sign in to comment.