<commit_before>require_relative '../spec_helper'

require_relative '../../app/models/visualization/collection'
require_relative '../../services/relocator/worker'
require_relative 'organization_shared_examples'

include CartoDB

describe 'refactored behaviour' do
  it_behaves_like 'organization models' do

    before(:each) do
      @the_organization = ::Organization.where(id: @organization.id).first
    end

    def get_twitter_imports_count_by_organization_id(organization_id)
      raise "id doesn't match" unless organization_id == @the_organization.id
      @the_organization.get_twitter_imports_count
    end

    def get_geocoding_calls_by_organization_id(organization_id)
      raise "id doesn't match" unless organization_id == @the_organization.id
      @the_organization.get_geocoding_calls
    end

  end
end

describe Organization do

  before(:all) do
    @user = create_user(:quota_in_bytes => 524288000, :table_quota => 500)
  end

  after(:all) do
    Visualization::Member.any_instance.stubs(:has_named_map?).returns(false)
    begin
      @user.destroy
    rescue
      # Silence error, can't do much more
    end
  end

  describe '#destroy_cascade' do
    it 'Destroys users and owner as well' do
      organization = Organization.new(quota_in_bytes: 1234567890, name: 'wadus', seats: 5).save

      owner = create_user(:quota_in_bytes => 524288000, :table_quota => 500)
      owner_org = CartoDB::UserOrganization.new(organization.id, owner.id)
      owner_org.promote_user_to_admin
      owner.reload
      organization.reload

      user = create_user(:quota_in_bytes => 524288000, :table_quota => 500)
      CartoDB::Relocator::Worker.organize(user, organization)
      user.save
      user.reload
      organization.reload

      organization.destroy_cascade
      Organization.where(id: organization.id).first.should be nil
      User.where(id: user.id).first.should be nil
      User.where(id: owner.id).first.should be nil
    end
  end



  describe '#add_user_to_org' do
    it 'Tests adding a user to an organization (but no owner)' do
      org_quota = 1234567890<commit_msg>Stub central<commit_after>require_relative '../spec_helper'

require_relative '../../app/models/visualization/collection'
require_relative '../../services/relocator/worker'
require_relative 'organization_shared_examples'

include CartoDB

describe 'refactored behaviour' do
  it_behaves_like 'organization models' do

    before(:each) do
      @the_organization = ::Organization.where(id: @organization.id).first
    end

    def get_twitter_imports_count_by_organization_id(organization_id)
      raise "id doesn't match" unless organization_id == @the_organization.id
      @the_organization.get_twitter_imports_count
    end

    def get_geocoding_calls_by_organization_id(organization_id)
      raise "id doesn't match" unless organization_id == @the_organization.id
      @the_organization.get_geocoding_calls
    end

  end
end

describe Organization do

  before(:all) do
    @user = create_user(:quota_in_bytes => 524288000, :table_quota => 500)
  end

  after(:all) do
    Visualization::Member.any_instance.stubs(:has_named_map?).returns(false)
    begin
      @user.destroy
    rescue
      # Silence error, can't do much more
    end
  end

  describe '#destroy_cascade' do
    it 'Destroys users and owner as well' do
      User.any_instance.stubs(:create_in_central).returns(true)
      User.any_instance.stubs(:update_in_central).returns(true)
      organization = Organization.new(quota_in_bytes: 1234567890, name: 'wadus', seats: 5).save

      owner = create_user(:quota_in_bytes => 524288000, :table_quota => 500)
      owner_org = CartoDB::UserOrganization.new(organization.id, owner.id)
      owner_org.promote_user_to_admin
      owner.reload
      organization.reload

      user = create_user(:quota_in_bytes => 524288000, :table_quota => 500)
      CartoDB::Relocator::Worker.organize(user, organization)
      user.save
      user.reload
      organization.reload

      organization.destroy_cascade
      Organization.where(id: organization.id).first.should be nil
      User.where(id: user.id).first.should be nil
      User.where(id: owner.id).first.should be nil
    end
  end



  describe '#add_user_to_org' do
    it 'Tests adding a user to an organization (but no owner)' do
      org_quota = 1234567890
{'fraction_non_alphanumeric': 0.09289491837203954, 'fraction_numerical': 0.02621292251092205, 'mean_word_length': 3.78021978021978, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '224694', 'n_tokens_mistral': 1486, 'n_tokens_neox': 1336, 'n_words': 290}