mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-12-12 16:51:14 -05:00
3e50313fdc
Since rspec-rails 3, the default installation creates two helper files: * `spec_helper.rb` * `rails_helper.rb` `spec_helper.rb` is intended as a way of running specs that do not require Rails, whereas `rails_helper.rb` loads Rails (as Discourse's current `spec_helper.rb` does). For more information: https://www.relishapp.com/rspec/rspec-rails/docs/upgrade#default-helper-files In this commit, I've simply replaced all instances of `spec_helper` with `rails_helper`, and renamed the original `spec_helper.rb`. This brings the Discourse project closer to the standard usage of RSpec in a Rails app. At present, every spec relies on loading Rails, but there are likely many that don't need to. In a future pull request, I hope to introduce a separate, minimal `spec_helper.rb` which can be used in tests which don't rely on Rails.
52 lines
1.4 KiB
Ruby
52 lines
1.4 KiB
Ruby
require 'rails_helper'
|
|
require 'tempfile'
|
|
|
|
describe GlobalSetting::EnvProvider do
|
|
it "can detect keys from env" do
|
|
ENV['DISCOURSE_BLA'] = '1'
|
|
ENV['DISCOURSE_BLA_2'] = '2'
|
|
expect(GlobalSetting::EnvProvider.new.keys).to include(:bla)
|
|
expect(GlobalSetting::EnvProvider.new.keys).to include(:bla_2)
|
|
end
|
|
end
|
|
describe GlobalSetting::FileProvider do
|
|
it "can parse a simple file" do
|
|
f = Tempfile.new('foo')
|
|
f.write(" # this is a comment\n")
|
|
f.write("\n")
|
|
f.write(" a = 1000 # this is a comment\n")
|
|
f.write("b = \"10 # = 00\" # this is a # comment\n")
|
|
f.write("c = \'10 # = 00\' # this is a # comment\n")
|
|
f.write("d =\n")
|
|
f.write("#f = 1\n")
|
|
f.write("a1 = 1\n")
|
|
f.close
|
|
|
|
provider = GlobalSetting::FileProvider.from(f.path)
|
|
|
|
expect(provider.lookup(:a,"")).to eq 1000
|
|
expect(provider.lookup(:b,"")).to eq "10 # = 00"
|
|
expect(provider.lookup(:c,"")).to eq "10 # = 00"
|
|
expect(provider.lookup(:d,"bob")).to eq nil
|
|
expect(provider.lookup(:e,"bob")).to eq "bob"
|
|
expect(provider.lookup(:f,"bob")).to eq "bob"
|
|
expect(provider.lookup(:a1,"")).to eq 1
|
|
|
|
expect(provider.keys.sort).to eq [:a, :a1, :b, :c, :d]
|
|
|
|
f.unlink
|
|
end
|
|
|
|
it "uses ERB" do
|
|
f = Tempfile.new('foo')
|
|
f.write("a = <%= 500 %> # this is a comment\n")
|
|
f.close
|
|
|
|
provider = GlobalSetting::FileProvider.from(f.path)
|
|
|
|
expect(provider.lookup(:a,"")).to eq 500
|
|
|
|
f.unlink
|
|
end
|
|
|
|
end
|