Sha256: d5cbb0647b4ee93b17bab67fe123121be8227fa45be24c6083c0acdee6688c3c

Contents?: true

Size: 881 Bytes

Versions: 22

Compression:

Stored size: 881 Bytes

Contents

require 'spec_helper'

describe Paperclip::RailsEnvironment do

  it "returns nil when Rails isn't defined" do
    resetting_rails_to(nil) do
      expect(Paperclip::RailsEnvironment.get).to be_nil
    end
  end

  it "returns nil when Rails.env isn't defined" do
    resetting_rails_to({}) do
      expect(Paperclip::RailsEnvironment.get).to be_nil
    end
  end

  it "returns the value of Rails.env if it is set" do
    resetting_rails_to(OpenStruct.new(env: "foo")) do
      expect(Paperclip::RailsEnvironment.get).to eq "foo"
    end
  end

  def resetting_rails_to(new_value)
    begin
      previous_rails = Object.send(:remove_const, "Rails")
      Object.const_set("Rails", new_value) unless new_value.nil?
      yield
    ensure
      Object.send(:remove_const, "Rails") if Object.const_defined?("Rails")
      Object.const_set("Rails", previous_rails)
    end
  end
end

Version data entries

22 entries across 22 versions & 5 rubygems

Version Path
kt-paperclip-5.4.0 spec/paperclip/rails_environment_spec.rb
kt-paperclip-4.4.0 spec/paperclip/rails_environment_spec.rb
paperclip-6.1.0 spec/paperclip/rails_environment_spec.rb
paperclip-6.0.0 spec/paperclip/rails_environment_spec.rb
paperclip-5.3.0 spec/paperclip/rails_environment_spec.rb
paperclip-5.2.1 spec/paperclip/rails_environment_spec.rb
paperclip-5.2.0 spec/paperclip/rails_environment_spec.rb
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/paperclip-5.1.0/spec/paperclip/rails_environment_spec.rb
paperclip-5.1.0 spec/paperclip/rails_environment_spec.rb
paperclip-5.0.0 spec/paperclip/rails_environment_spec.rb
paperclip-4.3.7 spec/paperclip/rails_environment_spec.rb
paperclip_jk-5.0.0.beta2 spec/paperclip/rails_environment_spec.rb
ish_lib_manager-0.0.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/paperclip-4.3.6/spec/paperclip/rails_environment_spec.rb
paperclip-5.0.0.beta2 spec/paperclip/rails_environment_spec.rb
paperclip-5.0.0.beta1 spec/paperclip/rails_environment_spec.rb
paperclip-4.3.6 spec/paperclip/rails_environment_spec.rb
paperclip-4.3.5 spec/paperclip/rails_environment_spec.rb
paperclip-4.3.4 spec/paperclip/rails_environment_spec.rb
paperclip-4.3.3 spec/paperclip/rails_environment_spec.rb
paperclip-4.3.2 spec/paperclip/rails_environment_spec.rb