mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-12-04 21:01:27 -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.
88 lines
1.7 KiB
Ruby
88 lines
1.7 KiB
Ruby
require "rails_helper"
|
|
require_dependency "plugin_store"
|
|
|
|
describe PluginStore do
|
|
def set(k,v)
|
|
PluginStore.set("my_plugin", k, v)
|
|
end
|
|
|
|
def get(k)
|
|
PluginStore.get("my_plugin", k)
|
|
end
|
|
|
|
def remove_row(k)
|
|
PluginStore.remove("my_plugin", k)
|
|
end
|
|
|
|
it "sets strings correctly" do
|
|
set("hello", "world")
|
|
expect(get("hello")).to eq("world")
|
|
|
|
set("hello", "world1")
|
|
expect(get("hello")).to eq("world1")
|
|
end
|
|
|
|
it "sets fixnums correctly" do
|
|
set("hello", 1)
|
|
expect(get("hello")).to eq(1)
|
|
end
|
|
|
|
it "sets bools correctly" do
|
|
set("hello", true)
|
|
expect(get("hello")).to eq(true)
|
|
|
|
set("hello", false)
|
|
expect(get("hello")).to eq(false)
|
|
|
|
set("hello", nil)
|
|
expect(get("hello")).to eq(nil)
|
|
end
|
|
|
|
|
|
it "handles hashes correctly" do
|
|
|
|
val = {"hi" => "there", "1" => 1}
|
|
set("hello", val)
|
|
result = get("hello")
|
|
|
|
expect(result).to eq(val)
|
|
|
|
# ensure indiff access holds
|
|
expect(result[:hi]).to eq("there")
|
|
end
|
|
|
|
it "handles nested hashes correctly" do
|
|
|
|
val = {"hi" => "there", "nested" => {"a" => "b", "with list" => ["a", "b", 3] }}
|
|
set("hello", val)
|
|
result = get("hello")
|
|
|
|
expect(result).to eq(val)
|
|
|
|
# ensure indiff access holds
|
|
expect(result[:hi]).to eq("there")
|
|
expect(result[:nested][:a]).to eq("b")
|
|
expect(result[:nested]["with list"]).to eq(["a", "b", 3])
|
|
end
|
|
|
|
it "handles arrays correctly" do
|
|
|
|
val = ["a", "b", {"hash"=> "inside", "c"=> 1}]
|
|
set("hello", val)
|
|
result = get("hello")
|
|
|
|
expect(result).to eq(val)
|
|
|
|
# ensure indiff access holds
|
|
expect(result[2][:hash]).to eq("inside")
|
|
expect(result[2]["c"]).to eq(1)
|
|
|
|
end
|
|
|
|
it "removes correctly" do
|
|
set("hello", true)
|
|
remove_row("hello")
|
|
expect(get("hello")).to eq(nil)
|
|
end
|
|
|
|
end
|