Skip to content
This repository has been archived by the owner on Aug 29, 2018. It is now read-only.

Commit

Permalink
Fix bug 1039591: Don't use url basename as suggested app name
Browse files Browse the repository at this point in the history
  • Loading branch information
liggitt committed Dec 11, 2013
1 parent 0bc5c7f commit 7928aac
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
12 changes: 10 additions & 2 deletions console/app/models/cartridge_type.rb
Expand Up @@ -57,18 +57,26 @@ def suggest_name
if name.present?
name_prefix
elsif url.present?
url_basename
url_suggested_name
end
end

def to_param
url || name
end

def url_basename
def url_suggested_name
uri = URI.parse(url)
name = uri.fragment
name = Rack::Utils.parse_nested_query(uri.query)['name'] if name.blank? && uri.query
name.presence
rescue
nil
end

def url_basename
uri = URI.parse(url)
name = url_suggested_name
name = File.basename(uri.path) if name.blank? && uri.path.present? && uri.path != '/'
name.presence || url
rescue
Expand Down
36 changes: 36 additions & 0 deletions console/test/functional/application_types_controller_test.rb
Expand Up @@ -288,6 +288,42 @@ def readable_domain(name="readable")
assert_nil assigns(:suggesting_name)
end

test "should suggest name from custom cart url with hash" do
with_unique_user
get :show, :id => 'custom', :application_type => {:cartridges => 'http://foo.bar#custom_cart'}
assert_response :success
assert_select 'h3', 'From Scratch'
assert_select '.text-warning', /Downloaded cartridges do not receive updates automatically/
assert_select "input[type=hidden][name='application[cartridges][][url]'][value=http://foo.bar#custom_cart]"
assert_select ".indicator-gear-increase", "+1"
assert_equal 'customcart', assigns(:application).name
assert assigns(:suggesting_name)
end

test "should suggest name from custom cart url with name param" do
with_unique_user
get :show, :id => 'custom', :application_type => {:cartridges => 'http://foo.bar?name=custom_cart'}
assert_response :success
assert_select 'h3', 'From Scratch'
assert_select '.text-warning', /Downloaded cartridges do not receive updates automatically/
assert_select "input[type=hidden][name='application[cartridges][][url]'][value=http://foo.bar?name=custom_cart]"
assert_select ".indicator-gear-increase", "+1"
assert_equal 'customcart', assigns(:application).name
assert assigns(:suggesting_name)
end

test "should not suggest name from custom cart url" do
with_unique_user
get :show, :id => 'custom', :application_type => {:cartridges => 'http://foo.bar'}
assert_response :success
assert_select 'h3', 'From Scratch'
assert_select '.text-warning', /Downloaded cartridges do not receive updates automatically/
assert_select "input[type=hidden][name='application[cartridges][][url]'][value=http://foo.bar]"
assert_select ".indicator-gear-increase", "+1"
assert_nil assigns(:application).name
assert_nil assigns(:suggesting_name)
end

test "should render custom cart type with a choice" do
with_unique_user
get :show, :id => 'custom', :cartridges => 'ruby'
Expand Down

0 comments on commit 7928aac

Please sign in to comment.