spec/models/named_maps_spec.rb
# Does all the work and stubbing required to create a private table with an associated visualization
# NOTE: Leaves stubbed calls to GET the template so they return the correct template data
Does all the work and stubbing required to create a private table with an associated visualization
NOTE: Leaves stubbed calls to GET the template so they return the correct template data
Does all the work and stubbing required to create a private table with an associated 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)
    table = create_table( user_id: @user.id )
    derived_vis = CartoDB::Visualization::Copier.new(@user, table.table_visualization).copy
    derived_vis.privacy = visualization_privacy
    template_id = CartoDB::NamedMapsWrapper::NamedMap.normalize_name(derived_vis.id)
    Typhoeus.stub( tiler_regex )
            .and_return(
              Typhoeus::Response.new(code: 404, body: '')
            )
    Typhoeus.stub( named_maps_url(@user.api_key) )
            .and_return(
              Typhoeus::Response.new( code: 200, body: JSON::dump( template_id: template_id ) )
            )
    derived_vis.store
    collection  = Visualization::Collection.new.fetch
    collection.add(derived_vis)
    collection.store
    template_data[:template][:name] = template_id
    Typhoeus::Expectation.clear
    Typhoeus.stub( named_map_url(template_id, @user.api_key), 
      { method: :get} )
            .and_return(
              Typhoeus::Response.new( code: 200, body: JSON::dump( template_data ) )
            )
    Typhoeus.stub( named_map_url(template_id, @user.api_key), 
        { method: :put} )
              .and_return(
                Typhoeus::Response.new( code: 200, body: JSON::dump( template_data ) )
              )
    Typhoeus.stub( "http://#{@user.username}.localhost.lan:#{public_tiler_port}/tiles/template/#{template_id}?api_key=#{@user.api_key}", 
      { method: :get} )
            .and_return(
              Typhoeus::Response.new( code: 200, body: JSON::dump( template_data ) )
            )
    return table, derived_vis, template_id
  end
def create_private_table_with_public_visualization ( template_data , visualization_privacy = CartoDB :: Visualization :: Member :: PRIVACY_PUBLIC ) table = create_table ( user_id : @user . id ) derived_vis = CartoDB :: Visualization :: Copier . new ( @user , table . table_visualization ) . copy derived_vis . privacy = visualization_privacy template_id = CartoDB :: NamedMapsWrapper :: NamedMap . normalize_name ( derived_vis . id ) Typhoeus . stub ( tiler_regex ) . and_return ( Typhoeus :: Response . new ( code : 404 , body : '' ) ) Typhoeus . stub ( named_maps_url ( @user . api_key ) ) . and_return ( Typhoeus :: Response . new ( code : 200 , body : JSON :: dump ( template_id : template_id ) ) ) derived_vis . store collection = Visualization :: Collection . new . fetch collection . add ( derived_vis ) collection . store template_data [ :template ] [ :name ] = template_id Typhoeus :: Expectation . clear Typhoeus . stub ( named_map_url ( template_id , @user . api_key ) , { method : :get } ) . and_return ( Typhoeus :: Response . new ( code : 200 , body : JSON :: dump ( template_data ) ) ) Typhoeus . stub ( named_map_url ( template_id , @user . api_key ) , { method : :put } ) . and_return ( Typhoeus :: Response . new ( code : 200 , body : JSON :: dump ( template_data ) ) ) Typhoeus . stub ( "http://#{@user.username}.localhost.lan:#{public_tiler_port}/tiles/template/#{template_id}?api_key=#{@user.api_key}" , { method : :get } ) . and_return ( Typhoeus :: Response . new ( code : 200 , body : JSON :: dump ( template_data ) ) ) return table , derived_vis , template_id end
Does all the work and stubbing required to create a private table with an associated visualization
NOTE: Leaves stubbed calls to GET the template so they return the correct template data
Does all the work and stubbing required to create a private table with an associated visualization NOTE : Leaves stubbed calls to GET the template so they return the correct template data
# Stub all petitions, not just GET # Retrievals # Updates # Vizjson uses the public endpoint, so stub it too
template_data
visualization_privacy