Skip to content

Commit

Permalink
#3897 spec stabilization
Browse files Browse the repository at this point in the history
  • Loading branch information
Kartones committed Jun 4, 2015
1 parent 6c144c0 commit 3be18e2
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 65 deletions.
2 changes: 2 additions & 0 deletions spec/models/automatic_geocoding_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
describe AutomaticGeocoding do
before(:all) do
@user = create_user(geocoding_quota: 200)

CartoDB::NamedMapsWrapper::NamedMaps.any_instance.stubs(:get => nil, :create => true, :update => true)
@table = FactoryGirl.create(:table, user_id: @user.id)
end

Expand Down
2 changes: 2 additions & 0 deletions spec/models/geocoding_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
describe Geocoding do
before(:all) do
@user = create_user(geocoding_quota: 200, geocoding_block_price: 1500)

CartoDB::NamedMapsWrapper::NamedMaps.any_instance.stubs(:get => nil, :create => true, :update => true)
@table = FactoryGirl.create(:user_table, user_id: @user.id)
end

Expand Down
99 changes: 34 additions & 65 deletions spec/models/named_maps_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,13 @@ def named_map_url(template_id, user_api_key)
}
}

# Post: to create (as now all tables/viz create named maps)
Typhoeus.stub( named_maps_url(@user.api_key),
{ method: :post } )
.and_return(
Typhoeus::Response.new( code: 200, body: JSON::dump( { template_id: 'tpl_fakeid' } ) )
)

table = create_table( user_id: @user.id )
table.privacy = UserTable::PRIVACY_PUBLIC
table.save()
Expand All @@ -134,12 +141,6 @@ def named_map_url(template_id, user_api_key)
derived_vis.privacy = CartoDB::Visualization::Member::PRIVACY_PROTECTED
derived_vis.password = password

# get: not present
Typhoeus.stub( tiler_regex,
{ method: :get} )
.and_return(
Typhoeus::Response.new(code: 404, body: "")
)
# Post: to create
Typhoeus.stub( named_maps_url(@user.api_key),
{ method: :post } )
Expand Down Expand Up @@ -168,7 +169,15 @@ def named_map_url(template_id, user_api_key)


describe 'public_table' do
it 'public map with public visualization does not create a named map' do
it 'public map with public visualization creates a named map' do
#Post to create
new_template_body = { template_id: 'tpl_fakeid' }

Typhoeus.stub( named_maps_url(@user.api_key) )
.and_return(
Typhoeus::Response.new( code: 200, body: JSON::dump( new_template_body ) )
)

table = create_table( user_id: @user.id )
table.privacy = UserTable::PRIVACY_PUBLIC
table.save()
Expand All @@ -190,11 +199,18 @@ def named_map_url(template_id, user_api_key)
table.affected_visualizations[1].id.should eq derived_vis.id
table.affected_visualizations[0].id.should_not eq table.affected_visualizations[1].id
end
end #public_table_public_vis

end

describe 'private_table' do
it 'private map with public visualization should create a named map' do
#Post to create
new_template_body = { template_id: 'tpl_fakeid' }

Typhoeus.stub( named_maps_url(@user.api_key) )
.and_return(
Typhoeus::Response.new( code: 200, body: JSON::dump( new_template_body ) )
)

table = create_table( user_id: @user.id )

derived_vis = CartoDB::Visualization::Copier.new(@user, table.table_visualization).copy()
Expand All @@ -206,14 +222,6 @@ def named_map_url(template_id, user_api_key)
Typhoeus::Response.new(code: 404, body: "")
)

#Post to create
new_template_body = { template_id: 'tpl_fakeid' }

Typhoeus.stub( named_maps_url(@user.api_key) )
.and_return(
Typhoeus::Response.new( code: 200, body: JSON::dump( new_template_body ) )
)

derived_vis.store()
collection = Visualization::Collection.new.fetch()
collection.add(derived_vis)
Expand Down Expand Up @@ -345,53 +353,6 @@ def named_map_url(template_id, user_api_key)
end #named_map_updated_on_visualization_updated


describe 'named_map_deleted_on_table_made_public' do
it 'checks that when you make a table public and the visualization had a named map, it gets deleted' do
template_data = {
template: {
version: '0.0.1',
name: '@@PLACEHOLDER@@',
auth: {
method: 'open'
},
placeholders: {
layer0: {
type: "number",
default: 1
}
},
layergroup: {
layers: [
{
type: "cartodb",
options: {
sql: "WITH wrapped_query AS (select * from test1) SELECT * from wrapped_query where <%= layer0 %>=1",
layer_name: "test1",
cartocss: "/** */",
cartocss_version: "2.1.1",
interactivity: "cartodb_id"
}
}
]
}
}
}

table, derived_vis, template_id = create_private_table_with_public_visualization(template_data)

Typhoeus.stub( named_map_url(template_id,@user.api_key),
{ method: :delete } )
.and_return(
Typhoeus::Response.new( code: 204, body: "" )
)

table.privacy = UserTable::PRIVACY_PUBLIC
table.save()
table.reload() # Will trigger a DELETE
end
end #named_map_updated_on_visualization_updated


describe 'only_torque_layer' do
it 'checks returned viz.json given a named map with only a torque layer' do

Expand Down Expand Up @@ -756,6 +717,14 @@ def get_vizjson(visualization)
# NOTE: Leaves stubbed calls to GET the template so they return the correct template data
def create_private_table_with_public_visualization(template_data,
visualization_privacy = CartoDB::Visualization::Member::PRIVACY_PUBLIC)

#Tables/canonical vis also nave named maps
new_template_body = { template_id: 'tpl_fakeid' }
Typhoeus.stub( named_maps_url(@user.api_key) )
.and_return(
Typhoeus::Response.new( code: 200, body: JSON::dump( new_template_body ) )
)

table = create_table( user_id: @user.id )
derived_vis = CartoDB::Visualization::Copier.new(@user, table.table_visualization).copy
derived_vis.privacy = visualization_privacy
Expand Down Expand Up @@ -801,6 +770,6 @@ def create_private_table_with_public_visualization(template_data,
)

return table, derived_vis, template_id
end #create_map_with_public_visualization
end

end

0 comments on commit 3be18e2

Please sign in to comment.