Permalink
Browse files

Merge pull request #414 from blj/fixes_to_upstream

fixed validate for config definitions
  • Loading branch information...
blj committed Mar 20, 2018
2 parents abb3001 + 5d4bcc7 commit 42dc455e7abc28b0748d6acb4905e5254c72b5a5
@@ -318,7 +318,8 @@ def update_cache
delegate :default, :type, :allow_blank?, :hidden?, :visible?, :settable?, :selection, :notes, :units, to: :definition
- def validate
+ validate :definition_must_be_valid
+ def definition_must_be_valid
definition.validate(self)
end
@@ -49,7 +49,7 @@
})
end
after :each do
- Radiant::Cache.clear
+ Radiant::Cache.clear if defined? Radiant::Cache
Radiant.detail.clear_definitions!
end
@@ -76,9 +76,9 @@
it "should validate against the supplied block" do
setting = Radiant::Config.find_by_key('valid')
- expect{setting.value = "Ape"}.to raise_error
+ expect{setting.value = "Ape"}.to raise_error(ActiveRecord::RecordInvalid)
expect(setting.valid?).to be false
- expect(setting.errors.on(:value)).to eq("That's no monkey")
+ expect(setting.errors[:value]).to include("That's no monkey")
end
it "should allow a valid value to be set" do
@@ -92,11 +92,11 @@
end
it "should not allow an invalid value to be set" do
- expect{Radiant::Config['valid'] = "Cow"}.to raise_error
+ expect{Radiant::Config['valid'] = "Cow"}.to raise_error(ActiveRecord::RecordInvalid)
expect(Radiant::Config['valid']).not_to eq("Cow")
- expect{Radiant::Config['selecting'] = "Pig"}.to raise_error
- expect{Radiant::Config['number'] = "Pig"}.to raise_error
- expect{Radiant::Config['required'] = ""}.to raise_error
+ expect{Radiant::Config['selecting'] = "Pig"}.to raise_error(ActiveRecord::RecordInvalid)
+ expect{Radiant::Config['number'] = "Pig"}.to raise_error(ActiveRecord::RecordInvalid)
+ expect{Radiant::Config['required'] = ""}.to raise_error(ActiveRecord::RecordInvalid)
end
end
@@ -149,7 +149,7 @@
end
it "should raise a validation error when a required value is made blank" do
- expect{ Radiant::Config['required'] = "" }.to raise_error
+ expect{ Radiant::Config['required'] = "" }.to raise_error(ActiveRecord::RecordInvalid)
end
end
@@ -1,5 +1,5 @@
require File.dirname(__FILE__) + "/../../spec_helper"
-
+require RADIANT_ROOT + "/lib/radiant/cache"
describe Radiant::Config do
before :each do
Radiant.detail.initialize_cache
View
@@ -1,8 +1,8 @@
# Configure Rails Envinronment
ENV["RAILS_ENV"] = "test"
# # require File.expand_path("../internal/config/environment.rb", __FILE__)
-# SPEC_ROOT = File.dirname(__FILE__)
-#
+SPEC_ROOT = File.dirname(__FILE__)
+
require 'rubygems'
require 'bundler/setup'

0 comments on commit 42dc455

Please sign in to comment.