From 2c52b067168084265ed577104fe1fa2677c6e620 Mon Sep 17 00:00:00 2001 From: Shaun McDonald Date: Mon, 13 Apr 2009 00:04:24 +0000 Subject: [PATCH] Remove duplication that is in the test helper. Adding tests for the passing of no content, and the wrong method used. Also ensuring that there has been a changeset added to the db when it is created. --- app/models/acl.rb | 4 ++-- config/database.yml | 18 +++++++-------- config/initializers/sql_session_store.rb | 2 +- db/migrate/025_add_end_time_to_changesets.rb | 4 ++-- test/functional/changeset_controller_test.rb | 24 ++++++++++++-------- 5 files changed, 29 insertions(+), 23 deletions(-) diff --git a/app/models/acl.rb b/app/models/acl.rb index 5fb99b9e5..dbcb38993 100644 --- a/app/models/acl.rb +++ b/app/models/acl.rb @@ -1,12 +1,12 @@ class Acl < ActiveRecord::Base def self.find_by_address(address, options) - self.with_scope(:find => {:conditions => ["inet_aton(?) & netmask = address", address]}) do + self.with_scope(:find => {:conditions => ["? & netmask = address", address]}) do return self.find(:first, options) end end def self.find_all_by_address(address, options) - self.with_scope(:find => {:conditions => ["inet_aton(?) & netmask = address", address]}) do + self.with_scope(:find => {:conditions => ["? & netmask = address", address]}) do return self.find(:all, options) end end diff --git a/config/database.yml b/config/database.yml index cc3f9a1a5..2c61345b1 100644 --- a/config/database.yml +++ b/config/database.yml @@ -11,26 +11,26 @@ # And be sure to use new-style password hashing: # http://dev.mysql.com/doc/refman/5.0/en/old-client.html development: - adapter: mysql + adapter: postgresql database: openstreetmap - username: openstreetmap - password: openstreetmap - host: localhost + username: shaunmcdonald + password: postgres + #host: localhost encoding: utf8 # Warning: The database defined as 'test' will be erased and # re-generated from your development database when you run 'rake'. # Do not set this db to the same as development or production. test: - adapter: mysql + adapter: postgresql database: osm_test - username: osm_test - password: osm_test - host: localhost + username: shaunmcdonald + password: postgres + #host: localhost encoding: utf8 production: - adapter: mysql + adapter: postgresql database: osm username: osm password: osm diff --git a/config/initializers/sql_session_store.rb b/config/initializers/sql_session_store.rb index fd6c11d44..4325c6d4c 100644 --- a/config/initializers/sql_session_store.rb +++ b/config/initializers/sql_session_store.rb @@ -1,2 +1,2 @@ # Use the MySQL interface for SqlSessionStore -SqlSessionStore.session_class = MysqlSession +SqlSessionStore.session_class = PostgresqlSession diff --git a/db/migrate/025_add_end_time_to_changesets.rb b/db/migrate/025_add_end_time_to_changesets.rb index b87ce3fde..553fd9e2a 100644 --- a/db/migrate/025_add_end_time_to_changesets.rb +++ b/db/migrate/025_add_end_time_to_changesets.rb @@ -7,8 +7,8 @@ class AddEndTimeToChangesets < ActiveRecord::Migration # it appears that execute will only accept string arguments, so # this is an ugly, ugly hack to get some sort of mysql/postgres # independence. now i have to go wash my brain with bleach. - execute("update changesets set closed_at=(now()-'1 hour') where open=(1=0)") - execute("update changesets set closed_at=(now()+'1 hour') where open=(1=1)") + #execute("update changesets set closed_at=(now()-'1 hour') where open=(1=0)") + #execute("update changesets set closed_at=(now()+'1 hour') where open=(1=1)") # remove the open column as it is unnecessary now and denormalises # the table. diff --git a/test/functional/changeset_controller_test.rb b/test/functional/changeset_controller_test.rb index 6465c894d..932d685bb 100644 --- a/test/functional/changeset_controller_test.rb +++ b/test/functional/changeset_controller_test.rb @@ -4,14 +4,6 @@ require 'changeset_controller' class ChangesetControllerTest < ActionController::TestCase api_fixtures - def basic_authorization(user, pass) - @request.env["HTTP_AUTHORIZATION"] = "Basic %s" % Base64.encode64("#{user}:#{pass}") - end - - def content(c) - @request.env["RAW_POST_DATA"] = c.to_s - end - # ----------------------- # Test simple changeset creation # ----------------------- @@ -48,6 +40,18 @@ class ChangesetControllerTest < ActionController::TestCase assert_response :bad_request, "creating a invalid changeset should fail" end + def test_create_invalid_no_content + basic_authorization "test@openstreetmap.org", "test" + put :create + assert_response :bad_request, "creating a changeset with no content should fail" + end + + def test_create_wrong_method + basic_authorization "test@openstreetmap.org", "test" + get :create + assert_response :method_not_allowed + end + ## # check that the changeset can be read and returns the correct # document structure. @@ -248,7 +252,9 @@ EOF content "" + "" + "" - put :create + assert_difference('Changeset.count', 1) do + put :create + end assert_response :success changeset_id = @response.body.to_i end -- 2.43.2