Created
June 27, 2011 12:39
-
-
Save darkofabijan/1048780 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Api::V2::MunicipalitiesController < Api::V2::BaseController | |
def index | |
municipalities = Municipality.find_all_for_api | |
@municipalities = municipalities.collect { |m| {:id => m.id, :name => m.name} } | |
render_json(@municipalities) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'spec_helper' | |
describe Api::V2::MunicipalitiesController do | |
let(:api_key) { mock_model(ApiKey, :key => "123") } | |
let(:municipality) { mock_model(Municipality, :name => "Munun.. 1") } | |
describe "GET 'index'" do | |
context "no municipalities" do | |
it "returns empty json" do | |
Municipality.should_receive(:find_all_for_api).and_return([]) | |
get :index, :format => 'json', :api_key => api_key.key | |
response.body.should == '[]' | |
end | |
end | |
context "two municipalities" do | |
it "returns json with names" do | |
Municipality.should_receive(:find_all_for_api).and_return([municipality]) | |
get :index, :format => 'json', :api_key => api_key.key | |
expected_response = %([{"name":"#{municipality.name}","id":#{municipality.id}}]') | |
response.body.should == expected_response | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment