<commit_before>require_relative '../../../spec_helper'
require_relative '../../../factories/users_helper'

describe Carto::Builder::VisualizationsController do
  include Warden::Test::Helpers

  include_context 'users helper'

  before(:all) do
    @user1.builder_enabled = true
    @user1.save
  end

  describe '#show' do
    before(:each) do
      map = FactoryGirl.create(:map, user_id: @user1.id)
      @visualization = FactoryGirl.create(:carto_visualization, user_id: @user1.id, map_id: map.id)
      login(@user1)
    end

    it 'redirects to embed for non-editor users requests' do
      @user1.stubs(:builder_enabled).returns(false)

      get builder_visualization_url(id: @visualization.id)

      response.status.should eq 302
      response.location.should end_with builder_visualization_public_embed_path(visualization_id: @visualization.id)
    end

    it 'redirects to editor for vizjson2 visualizations' do
      @visualization.version = 2
      @visualization.save
      Carto::Visualization.any_instance.stubs(:uses_vizjson2?).returns(true)

      get builder_visualization_url(id: @visualization.id)

      response.status.should eq 302<commit_msg>add viz iframe tests<commit_after>require_relative '../../../spec_helper'
require_relative '../../../factories/users_helper'

describe Carto::Builder::VisualizationsController do
  include Warden::Test::Helpers

  include_context 'users helper'

  before(:all) do
    @user1.builder_enabled = true
    @user1.save
  end

  describe '#show' do
    before(:each) do
      map = FactoryGirl.create(:map, user_id: @user1.id)
      @visualization = FactoryGirl.create(:carto_visualization, user_id: @user1.id, map_id: map.id)
      login(@user1)
    end

    it 'denies iframe for users without the allow_private_viz_iframe feature flag' do
      get builder_visualization_url(id: @visualization.id)
      
      response.status.should == 200
      response.headers['X-Frame-Options'].should == 'DENY'
    end

    it 'allows iframe for users without the allow_private_viz_iframe feature flag' do
      ff = FactoryGirl.create(:feature_flag, name: 'allow_private_viz_iframe')
      fuu = FactoryGirl.create(:feature_flags_user, feature_flag_id: ff.id, user_id: @user1.id)
      
      get builder_visualization_url(id: @visualization.id)
      
      response.status.should == 200
      response.headers['X-Frame-Options'].should be_nil
      fuu.destroy
    end

    it 'redirects to embed for non-editor users requests' do
      @user1.stubs(:builder_enabled).returns(false)

      get builder_visualization_url(id: @visualization.id)

      response.status.should eq 302
      response.location.should end_with builder_visualization_public_embed_path(visualization_id: @visualization.id)
    end

    it 'redirects to editor for vizjson2 visualizations' do
      @visualization.version = 2
      @visualization.save
      Carto::Visualization.any_instance.stubs(:uses_vizjson2?).returns(true)

      get builder_visualization_url(id: @visualization.id)

      response.status.should eq 302
{'fraction_non_alphanumeric': 0.1026814911706998, 'fraction_numerical': 0.01209941137998692, 'mean_word_length': 3.706153846153846, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5105860', 'n_tokens_mistral': 1004, 'n_tokens_neox': 920, 'n_words': 199}