Permalink
Browse files

Do not raise when there is a mismatch between db_schema and schema

  • Loading branch information...
mig-hub committed Sep 29, 2011
1 parent fa3deef commit c717df86dea0206487d9b3ee340fbd529fc7b91f
Showing with 25 additions and 3 deletions.
  1. +1 −0 README.md
  2. +2 −2 lib/sequel_crushyform.rb
  3. +1 −1 sequel-crushyform.gemspec
  4. +21 −0 test/spec_crushyform.rb
View
@@ -361,6 +361,7 @@ CHANGE LOG
0.1.1 Use strftime fordate/time (do not know why I did not !!!)
0.1.2 Monkey patch, just prevent to have text areas instead of text fields when using PostgreSQL
0.1.3 Still use the @schema value for :text type when :schema plugin is used
+0.1.4 Do not raise when there is a mismatch between db_schema and schema
COPYRIGHT
=========
View
@@ -1,15 +1,15 @@
module ::Sequel::Plugins::Crushyform
module ClassMethods
- def crushyform_version; [0,1,3]; end
+ def crushyform_version; [0,1,4]; end
# Schema
def crushyform_schema
@crushyform_schema ||= default_crushyform_schema
end
def default_crushyform_schema
out = {}
db_schema.each do |k,v|
- out[k] = if respond_to?(:schema) && @schema.columns.find{|c|c[:name]==k}[:type]==:text
+ out[k] = if respond_to?(:schema) && (@schema.columns.find{|c|c[:name]==k}||{:type=>nil})[:type]==:text
{:type=>:text} # Using :schema plugin is the safest
elsif [:sqlite,:mysql].include?(@db.database_type) && v[:db_type]=='text'
{:type=>:text} # Without :schema plugin Postgres uses text even for strings
@@ -1,6 +1,6 @@
Gem::Specification.new do |s|
s.name = 'sequel-crushyform'
- s.version = "0.1.3"
+ s.version = "0.1.4"
s.platform = Gem::Platform::RUBY
s.summary = "A Sequel plugin that helps building forms"
s.description = "A Sequel plugin that helps building forms. It basically does them for you so that you can forget about the boring part. The kind of thing which is good to have in your toolbox for building a CMS."
View
@@ -131,6 +131,19 @@ class Pic < ::Sequel::Model
class WithAccronymYMCAName < ::Sequel::Model; end
+DB.create_table :mismatches do
+ primary_key :id
+ String :title
+ text :body
+end
+class Mismatch < ::Sequel::Model
+ plugin :schema
+ set_schema do
+ primary_key :id
+ String :title
+ end
+end
+
# ========
# = Test =
# ========
@@ -173,6 +186,14 @@ class WithAccronymYMCAName < ::Sequel::Model; end
}
end
+ should 'not raise when there is a database column that is not in @schema' do
+ Mismatch.default_crushyform_schema.should=={
+ :title=>{:type=>:string},
+ :id=>{:type=>:integer},
+ :body=>{:type=>:text}
+ }
+ end
+
end
describe 'Crushyform miscellaneous helpers' do

0 comments on commit c717df8

Please sign in to comment.