From 986144a49c292bcb385117857bb68d7bbfc0f847 Mon Sep 17 00:00:00 2001 From: Xin Zheng Date: Tue, 22 Jan 2008 18:46:41 +0000 Subject: [PATCH] added some tests --- spec/controllers/api_controller_spec.rb | 55 +++++++++++++++++++++++++ spec/helpers/api_helper_spec.rb | 11 +++++ spec/spec_helper.rb | 2 + 3 files changed, 68 insertions(+) create mode 100644 spec/controllers/api_controller_spec.rb create mode 100644 spec/helpers/api_helper_spec.rb diff --git a/spec/controllers/api_controller_spec.rb b/spec/controllers/api_controller_spec.rb new file mode 100644 index 000000000..99f41c2a0 --- /dev/null +++ b/spec/controllers/api_controller_spec.rb @@ -0,0 +1,55 @@ +require File.dirname(__FILE__) + '/../spec_helper' + +module ApiMapHelpers + def self.included(klass) + klass.extend(ClassMethods) + end + + def boundary_params(key) + case key + when :valid + '-0.3565352711206896,51.464740877658045,-0.2686446461206896,51.508686190158045' + when :min_lat_more_than_max_lat + '-0.3565352711206896,-0.2686446461206896,51.508686190158045,51.464740877658045' + when :min_lon_more_than_max_lon + '51.464740877658045,-0.2686446461206896,51.508686190158045,-0.3565352711206896' + end + end + + module ClassMethods + def otherasdfa + end + end +end + +describe "When accessing /api/0.5/map" do + controller_name :api + include ApiMapHelpers + + before(:each) do + end + + it "should _return success_ with _correct boundary longitudes/latitudes_" do + get :map, :bbox => boundary_params(:valid) + response.should be_success + end + + it "should return an _error_ when _minimum longitude more than or equal to maximum longitude_" do + get :map, :bbox => boundary_params(:min_lat_more_than_max_lat) + response.should_not be_success + end + + it "should return an error unless minimum latitude less than maximum latitude" do + get :map, :bbox => boundary_params(:min_lon_more_than_max_lon) + response.should_not be_success + end + + it "should return an error unless latitudes are between -90 and 90 degrees" do + pending + end + + it "should return an error unless longitudes are between -180 and 180 degrees" do + pending + end + +end diff --git a/spec/helpers/api_helper_spec.rb b/spec/helpers/api_helper_spec.rb new file mode 100644 index 000000000..2f5f0ef5d --- /dev/null +++ b/spec/helpers/api_helper_spec.rb @@ -0,0 +1,11 @@ +require File.dirname(__FILE__) + '/../spec_helper' + +describe ApiHelper do + + #Delete this example and add some real ones or delete this file + it "should include the ApiHelper" do + included_modules = self.metaclass.send :included_modules + included_modules.should include(ApiHelper) + end + +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 210d9d196..9771836cb 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -5,6 +5,8 @@ require File.expand_path(File.dirname(__FILE__) + "/../config/environment") require 'spec' require 'spec/rails' +require 'ruby-debug' + Spec::Runner.configure do |config| # If you're not using ActiveRecord you should remove these # lines, delete config/database.yml and disable :active_record -- 2.43.2