mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-12-20 20:42:44 -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.
51 lines
1.3 KiB
Ruby
51 lines
1.3 KiB
Ruby
require 'rails_helper'
|
|
require_dependency 'site_settings/db_provider'
|
|
|
|
describe SiteSettings::DbProvider do
|
|
|
|
def expect_same_setting(actual, expected)
|
|
expect(actual.name).to eq(expected.name)
|
|
expect(actual.value).to eq(expected.value)
|
|
expect(actual.data_type).to eq(expected.data_type)
|
|
end
|
|
|
|
let :provider do
|
|
SiteSettings::DbProvider.new(SiteSetting)
|
|
end
|
|
|
|
# integration test, requires db access
|
|
it "act correctly" do
|
|
setting = Struct.new(:name, :value, :data_type)
|
|
|
|
SiteSetting.destroy_all
|
|
|
|
expect(provider.all.length).to eq(0)
|
|
expect(provider.find("test")).to eq(nil)
|
|
|
|
|
|
provider.save("test", "one", 1)
|
|
found = provider.find("test")
|
|
|
|
expect_same_setting(found, setting.new("test", "one", 1))
|
|
|
|
provider.save("test", "two", 2)
|
|
found = provider.find("test")
|
|
|
|
expect_same_setting(found, setting.new("test", "two", 2))
|
|
|
|
provider.save("test2", "three", 3)
|
|
|
|
all = provider.all.sort{|a,b| a.name <=> b.name}
|
|
|
|
expect_same_setting(all[0], setting.new("test", "two", 2))
|
|
expect_same_setting(all[1], setting.new("test2", "three", 3))
|
|
expect(all.length).to eq(2)
|
|
|
|
provider.destroy("test")
|
|
expect(provider.all.length).to eq(1)
|
|
end
|
|
|
|
it "returns the correct site name" do
|
|
expect(provider.current_site).to eq(RailsMultisite::ConnectionManagement.current_db)
|
|
end
|
|
end
|