def relation
- begin
- @relation = Relation.find(params[:id])
-
- @name = @relation.tags['name'].to_s
- if @name.length == 0:
- @name = "#" + @relation.id.to_s
- end
-
- @title = 'Relation | ' + (@name)
- @next = Relation.find(:first, :order => "id ASC", :conditions => [ "visible = true AND id > :id", { :id => @relation.id }] )
- @prev = Relation.find(:first, :order => "id DESC", :conditions => [ "visible = true AND id < :id", { :id => @relation.id }] )
- rescue ActiveRecord::RecordNotFound
- @type = "relation"
- render :action => "not_found", :status => :not_found
+ @relation = Relation.find(params[:id])
+
+ @name = @relation.tags['name'].to_s
+ if @name.length == 0:
+ @name = "#" + @relation.id.to_s
end
+
+ @title = 'Relation | ' + (@name)
+ @next = Relation.find(:first, :order => "id ASC", :conditions => [ "visible = true AND id > :id", { :id => @relation.id }] )
+ @prev = Relation.find(:first, :order => "id DESC", :conditions => [ "visible = true AND id < :id", { :id => @relation.id }] )
+ rescue ActiveRecord::RecordNotFound
+ @type = "relation"
+ render :action => "not_found", :status => :not_found
end
def relation_history
- begin
- @relation = Relation.find(params[:id])
+ @relation = Relation.find(params[:id])
- @name = @relation.tags['name'].to_s
- if @name.length == 0:
- @name = "#" + @relation.id.to_s
- end
-
- @title = 'Relation History | ' + (@name)
- rescue ActiveRecord::RecordNotFound
- @type = "relation"
- render :action => "not_found", :status => :not_found
+ @name = @relation.tags['name'].to_s
+ if @name.length == 0:
+ @name = "#" + @relation.id.to_s
end
+
+ @title = 'Relation History | ' + (@name)
+ rescue ActiveRecord::RecordNotFound
+ @type = "relation"
+ render :action => "not_found", :status => :not_found
end
def way
- begin
- @way = Way.find(params[:id])
+ @way = Way.find(params[:id])
- @name = @way.tags['name'].to_s
- if @name.length == 0:
- @name = "#" + @way.id.to_s
- end
-
- @title = 'Way | ' + (@name)
- @next = Way.find(:first, :order => "id ASC", :conditions => [ "visible = true AND id > :id", { :id => @way.id }] )
- @prev = Way.find(:first, :order => "id DESC", :conditions => [ "visible = true AND id < :id", { :id => @way.id }] )
- rescue ActiveRecord::RecordNotFound
- @type = "way"
- render :action => "not_found", :status => :not_found
+ @name = @way.tags['name'].to_s
+ if @name.length == 0:
+ @name = "#" + @way.id.to_s
end
+
+ @title = 'Way | ' + (@name)
+ @next = Way.find(:first, :order => "id ASC", :conditions => [ "visible = true AND id > :id", { :id => @way.id }] )
+ @prev = Way.find(:first, :order => "id DESC", :conditions => [ "visible = true AND id < :id", { :id => @way.id }] )
+ rescue ActiveRecord::RecordNotFound
+ @type = "way"
+ render :action => "not_found", :status => :not_found
end
def way_history
- begin
- @way = Way.find(params[:id])
+ @way = Way.find(params[:id])
- @name = @way.tags['name'].to_s
- if @name.length == 0:
- @name = "#" + @way.id.to_s
- end
-
- @title = 'Way History | ' + (@name)
- rescue ActiveRecord::RecordNotFound
- @type = "way"
- render :action => "not_found", :status => :not_found
+ @name = @way.tags['name'].to_s
+ if @name.length == 0:
+ @name = "#" + @way.id.to_s
end
+
+ @title = 'Way History | ' + (@name)
+ rescue ActiveRecord::RecordNotFound
+ @type = "way"
+ render :action => "not_found", :status => :not_found
end
def node
- begin
- @node = Node.find(params[:id])
+ @node = Node.find(params[:id])
- @name = @node.tags_as_hash['name'].to_s
- if @name.length == 0:
- @name = "#" + @node.id.to_s
- end
-
- @title = 'Node | ' + (@name)
- @next = Node.find(:first, :order => "id ASC", :conditions => [ "visible = true AND id > :id", { :id => @node.id }] )
- @prev = Node.find(:first, :order => "id DESC", :conditions => [ "visible = true AND id < :id", { :id => @node.id }] )
- rescue ActiveRecord::RecordNotFound
- @type = "node"
- render :action => "not_found", :status => :not_found
+ @name = @node.tags_as_hash['name'].to_s
+ if @name.length == 0:
+ @name = "#" + @node.id.to_s
end
+
+ @title = 'Node | ' + (@name)
+ @next = Node.find(:first, :order => "id ASC", :conditions => [ "visible = true AND id > :id", { :id => @node.id }] )
+ @prev = Node.find(:first, :order => "id DESC", :conditions => [ "visible = true AND id < :id", { :id => @node.id }] )
+ rescue ActiveRecord::RecordNotFound
+ @type = "node"
+ render :action => "not_found", :status => :not_found
end
def node_history
- begin
- @node = Node.find(params[:id])
+ @node = Node.find(params[:id])
- @name = @node.tags_as_hash['name'].to_s
- if @name.length == 0:
- @name = "#" + @node.id.to_s
- end
-
- @title = 'Node History | ' + (@name)
- rescue ActiveRecord::RecordNotFound
- @type = "way"
- render :action => "not_found", :status => :not_found
+ @name = @node.tags_as_hash['name'].to_s
+ if @name.length == 0:
+ @name = "#" + @node.id.to_s
end
+
+ @title = 'Node History | ' + (@name)
+ rescue ActiveRecord::RecordNotFound
+ @type = "way"
+ render :action => "not_found", :status => :not_found
end
def changeset
- begin
- @changeset = Changeset.find(params[:id])
- @node_pages, @nodes = paginate(:old_nodes, :conditions => {:changeset_id => @changeset.id}, :per_page => 20, :parameter => 'node_page')
- @way_pages, @ways = paginate(:old_ways, :conditions => {:changeset_id => @changeset.id}, :per_page => 20, :parameter => 'way_page')
- @relation_pages, @relations = paginate(:old_relations, :conditions => {:changeset_id => @changeset.id}, :per_page => 20, :parameter => 'relation_page')
+ @changeset = Changeset.find(params[:id])
+ @node_pages, @nodes = paginate(:old_nodes, :conditions => {:changeset_id => @changeset.id}, :per_page => 20, :parameter => 'node_page')
+ @way_pages, @ways = paginate(:old_ways, :conditions => {:changeset_id => @changeset.id}, :per_page => 20, :parameter => 'way_page')
+ @relation_pages, @relations = paginate(:old_relations, :conditions => {:changeset_id => @changeset.id}, :per_page => 20, :parameter => 'relation_page')
- @title = "Changeset | #{@changeset.id}"
- @next = Changeset.find(:first, :order => "id ASC", :conditions => [ "id > :id", { :id => @changeset.id }] )
- @prev = Changeset.find(:first, :order => "id DESC", :conditions => [ "id < :id", { :id => @changeset.id }] )
- rescue ActiveRecord::RecordNotFound
- @type = "changeset"
- render :action => "not_found", :status => :not_found
- end
+ @title = "Changeset | #{@changeset.id}"
+ @next = Changeset.find(:first, :order => "id ASC", :conditions => [ "id > :id", { :id => @changeset.id }] )
+ @prev = Changeset.find(:first, :order => "id DESC", :conditions => [ "id < :id", { :id => @changeset.id }] )
+ rescue ActiveRecord::RecordNotFound
+ @type = "changeset"
+ render :action => "not_found", :status => :not_found
end
end
class BrowseControllerTest < 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
-
- # We need to load the home page, then activate the start rjs method
- # and finally check that the new panel has loaded.
def test_start
-
+ get :start
+ assert_response :success
end
- # Test reading a relation
def test_read_relation
-
+ browse_check 'relation', relations(:visible_relation)
end
def test_read_relation_history
-
+ browse_check 'relation_history', relations(:visible_relation)
end
def test_read_way
-
+ browse_check 'way', ways(:visible_way)
end
def test_read_way_history
-
+ browse_check 'way_history', ways(:visible_way)
end
def test_read_node
-
+ browse_check 'node', nodes(:visible_node)
end
def test_read_node_history
-
+ browse_check 'node', nodes(:visible_node)
end
def test_read_changeset
-
+ browse_check 'changeset', changesets(:normal_user_first_change)
+ end
+
+ # This is a convenience method for most of the above checks
+ # First we check that when we don't have an id, it will correctly return a 404
+ # then we check that we get the correct 404 when a non-existant id is passed
+ # then we check that it will get a successful response, when we do pass an id
+ def browse_check(type, fixture)
+ get type
+ assert_response :not_found
+ assert_template 'not_found'
+ get type, {:id => -10} # we won't have an id that's negative
+ assert_response :not_found
+ assert_template 'not_found'
+ get type, {:id => fixture.id}
+ assert_response :success
+ assert_template type
end
end
require File.dirname(__FILE__) + '/../test_helper'
class UserControllerTest < ActionController::TestCase
- # Replace this with your real tests.
- def test_truth
- assert true
+ fixtures :users
+
+ # The user creation page loads
+ def test_user_create
+ get :new
+ assert_response :success
+
+ assert_select "html:root", :count => 1 do
+ assert_select "head", :count => 1 do
+ assert_select "title", :text => /create account/, :count => 1
+ end
+ assert_select "body", :count => 1 do
+ assert_select "div#content", :count => 1 do
+ assert_select "form[action='/user/save'][method=post]", :count => 1 do
+ assert_select "input[id=user_email]", :count => 1
+ assert_select "input[id=user_email_confirmation]", :count => 1
+ assert_select "input[id=user_display_name]", :count => 1
+ assert_select "input[id=user_pass_crypt][type=password]", :count => 1
+ assert_select "input[id=user_pass_crypt_confirmation][type=password]", :count => 1
+ assert_select "input[type=submit][value=Signup]", :count => 1
+ end
+ end
+ end
+ end
+ end
+
+ # Check that the user account page will display and contains some relevant
+ # information for the user
+ def test_view_user_account
+ get :view
+ assert_response :not_found
+
+ get :view, {:display_name => "test"}
+ assert_response :success
+ end
+
+ def test_user_api_details
+ get :api_details
+ assert_response :unauthorized
+
+ basic_authorization(users(:normal_user).email, "test")
+ get :api_details
+ assert_response :success
end
end