mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-23 23:58:31 -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.
89 lines
2.8 KiB
Ruby
89 lines
2.8 KiB
Ruby
require 'rails_helper'
|
|
|
|
describe IntegerSettingValidator do
|
|
describe '#valid_value?' do
|
|
|
|
shared_examples "for all IntegerSettingValidator opts" do
|
|
it "returns false for blank values" do
|
|
expect(validator.valid_value?('')).to eq(false)
|
|
expect(validator.valid_value?(nil)).to eq(false)
|
|
end
|
|
|
|
it "returns false if value is not a valid integer" do
|
|
expect(validator.valid_value?('two')).to eq(false)
|
|
end
|
|
end
|
|
|
|
context "without min and max" do
|
|
subject(:validator) { described_class.new }
|
|
|
|
include_examples "for all IntegerSettingValidator opts"
|
|
|
|
it "returns true if value is a valid integer" do
|
|
expect(validator.valid_value?(1)).to eq(true)
|
|
expect(validator.valid_value?(-1)).to eq(true)
|
|
expect(validator.valid_value?('1')).to eq(true)
|
|
expect(validator.valid_value?('-1')).to eq(true)
|
|
end
|
|
end
|
|
|
|
context "with min" do
|
|
subject(:validator) { described_class.new(min: 2) }
|
|
|
|
include_examples "for all IntegerSettingValidator opts"
|
|
|
|
it "returns true if value is equal to min" do
|
|
expect(validator.valid_value?(2)).to eq(true)
|
|
expect(validator.valid_value?('2')).to eq(true)
|
|
end
|
|
|
|
it "returns true if value is greater than min" do
|
|
expect(validator.valid_value?(3)).to eq(true)
|
|
expect(validator.valid_value?('3')).to eq(true)
|
|
end
|
|
|
|
it "returns false if value is less than min" do
|
|
expect(validator.valid_value?(1)).to eq(false)
|
|
expect(validator.valid_value?('1')).to eq(false)
|
|
end
|
|
end
|
|
|
|
context "with max" do
|
|
subject(:validator) { described_class.new(max: 3) }
|
|
|
|
include_examples "for all IntegerSettingValidator opts"
|
|
|
|
it "returns true if value is equal to max" do
|
|
expect(validator.valid_value?(3)).to eq(true)
|
|
expect(validator.valid_value?('3')).to eq(true)
|
|
end
|
|
|
|
it "returns true if value is less than max" do
|
|
expect(validator.valid_value?(2)).to eq(true)
|
|
expect(validator.valid_value?('2')).to eq(true)
|
|
end
|
|
|
|
it "returns false if value is greater than min" do
|
|
expect(validator.valid_value?(4)).to eq(false)
|
|
expect(validator.valid_value?('4')).to eq(false)
|
|
end
|
|
end
|
|
|
|
context "with min and max" do
|
|
subject(:validator) { described_class.new(min: -1, max: 3) }
|
|
|
|
include_examples "for all IntegerSettingValidator opts"
|
|
|
|
it "returns true if value is in range" do
|
|
expect(validator.valid_value?(-1)).to eq(true)
|
|
expect(validator.valid_value?(0)).to eq(true)
|
|
expect(validator.valid_value?(3)).to eq(true)
|
|
end
|
|
|
|
it "returns false if value is out of range" do
|
|
expect(validator.valid_value?(4)).to eq(false)
|
|
expect(validator.valid_value?(-2)).to eq(false)
|
|
end
|
|
end
|
|
end
|
|
end
|