Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'rspec/core/rake_task'

RSpec::Core::RakeTask::new(:spec) do |spec|
spec.fail_on_error = false
end

task :default => :spec
5 changes: 5 additions & 0 deletions gemfiles/Gemfile-rails2
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
source "http://rubygems.org"

gemspec :path => File.expand_path('../..', __FILE__)
gem "rails", "~> 2.3"
File.open(File.expand_path("../Gemfile-shared", __FILE__)){|f| eval(f.read)}
49 changes: 49 additions & 0 deletions gemfiles/Gemfile-rails2.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
PATH
remote: /home/lite/work/validates_xml
specs:
validates_xml (1.0.2)
activerecord (>= 2.0.0)

GEM
remote: http://rubygems.org/
specs:
actionmailer (2.3.14)
actionpack (= 2.3.14)
actionpack (2.3.14)
activesupport (= 2.3.14)
rack (~> 1.1.0)
activerecord (2.3.14)
activesupport (= 2.3.14)
activeresource (2.3.14)
activesupport (= 2.3.14)
activesupport (2.3.14)
diff-lcs (1.1.3)
rack (1.1.2)
rails (2.3.14)
actionmailer (= 2.3.14)
actionpack (= 2.3.14)
activerecord (= 2.3.14)
activeresource (= 2.3.14)
activesupport (= 2.3.14)
rake (>= 0.8.3)
rake (0.9.2)
rspec (2.6.0)
rspec-core (~> 2.6.0)
rspec-expectations (~> 2.6.0)
rspec-mocks (~> 2.6.0)
rspec-core (2.6.4)
rspec-expectations (2.6.0)
diff-lcs (~> 1.1.2)
rspec-mocks (2.6.0)
sqlite3 (1.3.4)
sqlite3-ruby (1.3.3)
sqlite3 (>= 1.3.3)

PLATFORMS
ruby

DEPENDENCIES
rails (~> 2.3)
rspec (~> 2.6.0)
sqlite3-ruby
validates_xml!
5 changes: 5 additions & 0 deletions gemfiles/Gemfile-rails3
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
source "http://rubygems.org"

gemspec :path => File.expand_path('../..', __FILE__)
gem "rails", "~> 3.0.0"
File.open(File.expand_path("../Gemfile-shared", __FILE__)){|f| eval(f.read)}
95 changes: 95 additions & 0 deletions gemfiles/Gemfile-rails3.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
PATH
remote: /home/lite/work/validates_xml
specs:
validates_xml (1.0.2)
activerecord (>= 2.0.0)

GEM
remote: http://rubygems.org/
specs:
abstract (1.0.0)
actionmailer (3.0.10)
actionpack (= 3.0.10)
mail (~> 2.2.19)
actionpack (3.0.10)
activemodel (= 3.0.10)
activesupport (= 3.0.10)
builder (~> 2.1.2)
erubis (~> 2.6.6)
i18n (~> 0.5.0)
rack (~> 1.2.1)
rack-mount (~> 0.6.14)
rack-test (~> 0.5.7)
tzinfo (~> 0.3.23)
activemodel (3.0.10)
activesupport (= 3.0.10)
builder (~> 2.1.2)
i18n (~> 0.5.0)
activerecord (3.0.10)
activemodel (= 3.0.10)
activesupport (= 3.0.10)
arel (~> 2.0.10)
tzinfo (~> 0.3.23)
activeresource (3.0.10)
activemodel (= 3.0.10)
activesupport (= 3.0.10)
activesupport (3.0.10)
arel (2.0.10)
builder (2.1.2)
diff-lcs (1.1.3)
erubis (2.6.6)
abstract (>= 1.0.0)
i18n (0.5.0)
mail (2.2.19)
activesupport (>= 2.3.6)
i18n (>= 0.4.0)
mime-types (~> 1.16)
treetop (~> 1.4.8)
mime-types (1.16)
polyglot (0.3.2)
rack (1.2.4)
rack-mount (0.6.14)
rack (>= 1.0.0)
rack-test (0.5.7)
rack (>= 1.0)
rails (3.0.10)
actionmailer (= 3.0.10)
actionpack (= 3.0.10)
activerecord (= 3.0.10)
activeresource (= 3.0.10)
activesupport (= 3.0.10)
bundler (~> 1.0)
railties (= 3.0.10)
railties (3.0.10)
actionpack (= 3.0.10)
activesupport (= 3.0.10)
rake (>= 0.8.7)
rdoc (~> 3.4)
thor (~> 0.14.4)
rake (0.9.2)
rdoc (3.6.1)
rspec (2.6.0)
rspec-core (~> 2.6.0)
rspec-expectations (~> 2.6.0)
rspec-mocks (~> 2.6.0)
rspec-core (2.6.4)
rspec-expectations (2.6.0)
diff-lcs (~> 1.1.2)
rspec-mocks (2.6.0)
sqlite3 (1.3.4)
sqlite3-ruby (1.3.3)
sqlite3 (>= 1.3.3)
thor (0.14.6)
treetop (1.4.10)
polyglot
polyglot (>= 0.3.1)
tzinfo (0.3.30)

PLATFORMS
ruby

DEPENDENCIES
rails (~> 3.0.0)
rspec (~> 2.6.0)
sqlite3-ruby
validates_xml!
2 changes: 2 additions & 0 deletions gemfiles/Gemfile-shared
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
gem "sqlite3-ruby"
gem "rspec", "~> 2.6.0"
2 changes: 2 additions & 0 deletions lib/validates_xml.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'active_record'

module ValidatesXML
def self.validates_xml(xml, options={})
begin
Expand Down
7 changes: 7 additions & 0 deletions runspecs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env ruby

%w[rails2 rails3].each do |rails|
ENV["BUNDLE_GEMFILE"] = "gemfiles/Gemfile-#{rails}"
system("bundle exec rake spec")
end

36 changes: 36 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
require 'bundler'
Bundler.require
require 'rexml/document'

Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}

ActiveRecord::Migration.verbose = false
ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")

RSpec.configure do |config|
config.before(:all) do
create_database
end

config.after(:all) do
drop_database
end

config.extend Rails3::Execute
end

def create_database
ActiveRecord::Schema.define(:version => 1) do
create_table :models do |t|
t.string :xml
t.string :xml_helper
end
end
end

def drop_database
ActiveRecord::Base.connection.tables.each do |table|
ActiveRecord::Base.connection.drop_table(table)
end
end
4 changes: 4 additions & 0 deletions spec/support/model.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class Model < ActiveRecord::Base
validates_xml :xml
validates :xml_helper, :xml_format => true if ActiveRecord::VERSION::MAJOR > 2
end
9 changes: 9 additions & 0 deletions spec/support/rails3.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module Rails3
module Execute
def rails3(&block)
if ActiveRecord::VERSION::MAJOR > 2
block.call
end
end
end
end
27 changes: 27 additions & 0 deletions spec/validates_xml_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
require 'spec_helper'

describe "validates_xml" do
it "validation should pass the correct XML (with helper)" do
@model = Model.new(:xml => "<xml>hello</xml>")
@model.xml_helper = "<xml>hello</xml>"
@model.should be_valid
end

it "validation should not pass the incorrect XML (with helper)" do
@model = Model.new(:xml => "<xml>hello<.xml>")
@model.xml_helper = "<xml>hello<.xml>"
@model.should_not be_valid
end

rails3 do
it "validation should pass correct XML" do
@model = Model.new(:xml_helper => "<xml>hello</xml>")
@model.should be_valid
end

it "validation should not pass incorrect XML" do
@model = Model.new(:xml_helper => "<xml>hello<.xml>")
@model.should_not be_valid
end
end
end