From 69822e40d680d8bdb6faeff903b7aea15d23830a Mon Sep 17 00:00:00 2001 From: Brian Landau Date: Fri, 26 Sep 2014 14:11:57 -0600 Subject: [PATCH] Add Travis build --- .travis.yml | 14 ++++ Appraisals | 19 +++++ README.markdown | 2 +- Rakefile | 2 + gemfiles/rails_30.gemfile | 7 ++ gemfiles/rails_30.gemfile.lock | 97 +++++++++++++++++++++++++ gemfiles/rails_31.gemfile | 7 ++ gemfiles/rails_31.gemfile.lock | 108 ++++++++++++++++++++++++++++ gemfiles/rails_32.gemfile | 7 ++ gemfiles/rails_32.gemfile.lock | 106 +++++++++++++++++++++++++++ gemfiles/rails_40.gemfile | 7 ++ gemfiles/rails_40.gemfile.lock | 94 ++++++++++++++++++++++++ gemfiles/rails_41.gemfile | 7 ++ gemfiles/rails_41.gemfile.lock | 100 ++++++++++++++++++++++++++ serialize_with_options.gemspec | 3 +- test/serialize_with_options_test.rb | 11 ++- test/test_helper.rb | 25 ++++++- 17 files changed, 611 insertions(+), 5 deletions(-) create mode 100644 .travis.yml create mode 100644 Appraisals create mode 100644 gemfiles/rails_30.gemfile create mode 100644 gemfiles/rails_30.gemfile.lock create mode 100644 gemfiles/rails_31.gemfile create mode 100644 gemfiles/rails_31.gemfile.lock create mode 100644 gemfiles/rails_32.gemfile create mode 100644 gemfiles/rails_32.gemfile.lock create mode 100644 gemfiles/rails_40.gemfile create mode 100644 gemfiles/rails_40.gemfile.lock create mode 100644 gemfiles/rails_41.gemfile create mode 100644 gemfiles/rails_41.gemfile.lock diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..ffa82a9 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,14 @@ +language: ruby +rvm: + - "1.9.3" + - "2.0.0" + - "2.1.0" + - "2.1.1" + - "2.1.2" + - "2.1.3" +gemfile: + - gemfiles/rails_30.gemfile + - gemfiles/rails_31.gemfile + - gemfiles/rails_32.gemfile + - gemfiles/rails_40.gemfile + - gemfiles/rails_41.gemfile diff --git a/Appraisals b/Appraisals new file mode 100644 index 0000000..6bfaeec --- /dev/null +++ b/Appraisals @@ -0,0 +1,19 @@ +appraise "rails-30" do + gem "rails", "~> 3.0.20" +end + +appraise "rails-31" do + gem "rails", "~> 3.1.12" +end + +appraise "rails-32" do + gem "rails", "~> 3.2.19" +end + +appraise "rails-40" do + gem "rails", "~> 4.0.10" +end + +appraise "rails-41" do + gem "rails", "~> 4.1.6" +end diff --git a/README.markdown b/README.markdown index f87f758..e7de146 100644 --- a/README.markdown +++ b/README.markdown @@ -1,7 +1,7 @@ SerializeWithOptions ==================== -[![Code Climate](https://codeclimate.com/github/vigetlabs/serialize_with_options.png)](https://codeclimate.com/github/vigetlabs/serialize_with_options) +[![Code Climate](https://codeclimate.com/github/vigetlabs/serialize_with_options.png)](https://codeclimate.com/github/vigetlabs/serialize_with_options) [![Build Status](https://travis-ci.org/vigetlabs/serialize_with_options.png?branch=master)](https://travis-ci.org/vigetlabs/serialize_with_options) This plugin is designed to make creating XML and JSON APIs for your Rails apps dead simple. We noticed a lot of repetition when creating API responses in our controllers. With this plugin, you can set the serialization options for a model with a simple DSL, rather than repeating them in every controller that includes it. diff --git a/Rakefile b/Rakefile index 158cc51..ad81975 100644 --- a/Rakefile +++ b/Rakefile @@ -7,3 +7,5 @@ Rake::TestTask.new(:test) do |test| test.pattern = 'test/*.rb' test.verbose = true end + +task :default => :test diff --git a/gemfiles/rails_30.gemfile b/gemfiles/rails_30.gemfile new file mode 100644 index 0000000..eef4df6 --- /dev/null +++ b/gemfiles/rails_30.gemfile @@ -0,0 +1,7 @@ +# This file was generated by Appraisal + +source "http://rubygems.org" + +gem "rails", "~> 3.0.20" + +gemspec :path => "../" diff --git a/gemfiles/rails_30.gemfile.lock b/gemfiles/rails_30.gemfile.lock new file mode 100644 index 0000000..894c41e --- /dev/null +++ b/gemfiles/rails_30.gemfile.lock @@ -0,0 +1,97 @@ +PATH + remote: ../ + specs: + serialize_with_options (0.3.0) + activerecord (>= 3.0) + +GEM + remote: http://rubygems.org/ + specs: + abstract (1.0.0) + actionmailer (3.0.20) + actionpack (= 3.0.20) + mail (~> 2.2.19) + actionpack (3.0.20) + activemodel (= 3.0.20) + activesupport (= 3.0.20) + builder (~> 2.1.2) + erubis (~> 2.6.6) + i18n (~> 0.5.0) + rack (~> 1.2.5) + rack-mount (~> 0.6.14) + rack-test (~> 0.5.7) + tzinfo (~> 0.3.23) + activemodel (3.0.20) + activesupport (= 3.0.20) + builder (~> 2.1.2) + i18n (~> 0.5.0) + activerecord (3.0.20) + activemodel (= 3.0.20) + activesupport (= 3.0.20) + arel (~> 2.0.10) + tzinfo (~> 0.3.23) + activeresource (3.0.20) + activemodel (= 3.0.20) + activesupport (= 3.0.20) + activesupport (3.0.20) + appraisal (1.0.2) + bundler + rake + thor (>= 0.14.0) + arel (2.0.10) + builder (2.1.2) + erubis (2.6.6) + abstract (>= 1.0.0) + i18n (0.5.4) + json (1.8.1) + mail (2.2.20) + activesupport (>= 2.3.6) + i18n (>= 0.4.0) + mime-types (~> 1.16) + treetop (~> 1.4.8) + mime-types (1.25.1) + polyglot (0.3.5) + rack (1.2.8) + rack-mount (0.6.14) + rack (>= 1.0.0) + rack-test (0.5.7) + rack (>= 1.0) + rails (3.0.20) + actionmailer (= 3.0.20) + actionpack (= 3.0.20) + activerecord (= 3.0.20) + activeresource (= 3.0.20) + activesupport (= 3.0.20) + bundler (~> 1.0) + railties (= 3.0.20) + railties (3.0.20) + actionpack (= 3.0.20) + activesupport (= 3.0.20) + rake (>= 0.8.7) + rdoc (~> 3.4) + thor (~> 0.14.4) + rake (10.3.2) + rdoc (3.12.2) + json (~> 1.4) + shoulda (3.5.0) + shoulda-context (~> 1.0, >= 1.0.1) + shoulda-matchers (>= 1.4.1, < 3.0) + shoulda-context (1.2.1) + shoulda-matchers (2.7.0) + activesupport (>= 3.0.0) + sqlite3 (1.3.9) + thor (0.14.6) + treetop (1.4.15) + polyglot + polyglot (>= 0.3.1) + tzinfo (0.3.41) + +PLATFORMS + ruby + +DEPENDENCIES + appraisal + rails (~> 3.0.20) + serialize_with_options! + shoulda + sqlite3 diff --git a/gemfiles/rails_31.gemfile b/gemfiles/rails_31.gemfile new file mode 100644 index 0000000..bc75ec8 --- /dev/null +++ b/gemfiles/rails_31.gemfile @@ -0,0 +1,7 @@ +# This file was generated by Appraisal + +source "http://rubygems.org" + +gem "rails", "~> 3.1.12" + +gemspec :path => "../" diff --git a/gemfiles/rails_31.gemfile.lock b/gemfiles/rails_31.gemfile.lock new file mode 100644 index 0000000..d1da379 --- /dev/null +++ b/gemfiles/rails_31.gemfile.lock @@ -0,0 +1,108 @@ +PATH + remote: ../ + specs: + serialize_with_options (0.3.0) + activerecord (>= 3.0) + +GEM + remote: http://rubygems.org/ + specs: + actionmailer (3.1.12) + actionpack (= 3.1.12) + mail (~> 2.4.4) + actionpack (3.1.12) + activemodel (= 3.1.12) + activesupport (= 3.1.12) + builder (~> 3.0.0) + erubis (~> 2.7.0) + i18n (~> 0.6) + rack (~> 1.3.6) + rack-cache (~> 1.2) + rack-mount (~> 0.8.2) + rack-test (~> 0.6.1) + sprockets (~> 2.0.4) + activemodel (3.1.12) + activesupport (= 3.1.12) + builder (~> 3.0.0) + i18n (~> 0.6) + activerecord (3.1.12) + activemodel (= 3.1.12) + activesupport (= 3.1.12) + arel (~> 2.2.3) + tzinfo (~> 0.3.29) + activeresource (3.1.12) + activemodel (= 3.1.12) + activesupport (= 3.1.12) + activesupport (3.1.12) + multi_json (~> 1.0) + appraisal (1.0.2) + bundler + rake + thor (>= 0.14.0) + arel (2.2.3) + builder (3.0.4) + erubis (2.7.0) + hike (1.2.3) + i18n (0.6.11) + json (1.8.1) + mail (2.4.4) + i18n (>= 0.4.0) + mime-types (~> 1.16) + treetop (~> 1.4.8) + mime-types (1.25.1) + multi_json (1.10.1) + polyglot (0.3.5) + rack (1.3.10) + rack-cache (1.2) + rack (>= 0.4) + rack-mount (0.8.3) + rack (>= 1.0.0) + rack-ssl (1.3.4) + rack + rack-test (0.6.2) + rack (>= 1.0) + rails (3.1.12) + actionmailer (= 3.1.12) + actionpack (= 3.1.12) + activerecord (= 3.1.12) + activeresource (= 3.1.12) + activesupport (= 3.1.12) + bundler (~> 1.0) + railties (= 3.1.12) + railties (3.1.12) + actionpack (= 3.1.12) + activesupport (= 3.1.12) + rack-ssl (~> 1.3.2) + rake (>= 0.8.7) + rdoc (~> 3.4) + thor (~> 0.14.6) + rake (10.3.2) + rdoc (3.12.2) + json (~> 1.4) + shoulda (3.5.0) + shoulda-context (~> 1.0, >= 1.0.1) + shoulda-matchers (>= 1.4.1, < 3.0) + shoulda-context (1.2.1) + shoulda-matchers (2.7.0) + activesupport (>= 3.0.0) + sprockets (2.0.4) + hike (~> 1.2) + rack (~> 1.0) + tilt (~> 1.1, != 1.3.0) + sqlite3 (1.3.9) + thor (0.14.6) + tilt (1.4.1) + treetop (1.4.15) + polyglot + polyglot (>= 0.3.1) + tzinfo (0.3.41) + +PLATFORMS + ruby + +DEPENDENCIES + appraisal + rails (~> 3.1.12) + serialize_with_options! + shoulda + sqlite3 diff --git a/gemfiles/rails_32.gemfile b/gemfiles/rails_32.gemfile new file mode 100644 index 0000000..9ef3452 --- /dev/null +++ b/gemfiles/rails_32.gemfile @@ -0,0 +1,7 @@ +# This file was generated by Appraisal + +source "http://rubygems.org" + +gem "rails", "~> 3.2.19" + +gemspec :path => "../" diff --git a/gemfiles/rails_32.gemfile.lock b/gemfiles/rails_32.gemfile.lock new file mode 100644 index 0000000..3910e8e --- /dev/null +++ b/gemfiles/rails_32.gemfile.lock @@ -0,0 +1,106 @@ +PATH + remote: ../ + specs: + serialize_with_options (0.3.0) + activerecord (>= 3.0) + +GEM + remote: http://rubygems.org/ + specs: + actionmailer (3.2.19) + actionpack (= 3.2.19) + mail (~> 2.5.4) + actionpack (3.2.19) + activemodel (= 3.2.19) + activesupport (= 3.2.19) + builder (~> 3.0.0) + erubis (~> 2.7.0) + journey (~> 1.0.4) + rack (~> 1.4.5) + rack-cache (~> 1.2) + rack-test (~> 0.6.1) + sprockets (~> 2.2.1) + activemodel (3.2.19) + activesupport (= 3.2.19) + builder (~> 3.0.0) + activerecord (3.2.19) + activemodel (= 3.2.19) + activesupport (= 3.2.19) + arel (~> 3.0.2) + tzinfo (~> 0.3.29) + activeresource (3.2.19) + activemodel (= 3.2.19) + activesupport (= 3.2.19) + activesupport (3.2.19) + i18n (~> 0.6, >= 0.6.4) + multi_json (~> 1.0) + appraisal (1.0.2) + bundler + rake + thor (>= 0.14.0) + arel (3.0.3) + builder (3.0.4) + erubis (2.7.0) + hike (1.2.3) + i18n (0.6.11) + journey (1.0.4) + json (1.8.1) + mail (2.5.4) + mime-types (~> 1.16) + treetop (~> 1.4.8) + mime-types (1.25.1) + multi_json (1.10.1) + polyglot (0.3.5) + rack (1.4.5) + rack-cache (1.2) + rack (>= 0.4) + rack-ssl (1.3.4) + rack + rack-test (0.6.2) + rack (>= 1.0) + rails (3.2.19) + actionmailer (= 3.2.19) + actionpack (= 3.2.19) + activerecord (= 3.2.19) + activeresource (= 3.2.19) + activesupport (= 3.2.19) + bundler (~> 1.0) + railties (= 3.2.19) + railties (3.2.19) + actionpack (= 3.2.19) + activesupport (= 3.2.19) + rack-ssl (~> 1.3.2) + rake (>= 0.8.7) + rdoc (~> 3.4) + thor (>= 0.14.6, < 2.0) + rake (10.3.2) + rdoc (3.12.2) + json (~> 1.4) + shoulda (3.5.0) + shoulda-context (~> 1.0, >= 1.0.1) + shoulda-matchers (>= 1.4.1, < 3.0) + shoulda-context (1.2.1) + shoulda-matchers (2.7.0) + activesupport (>= 3.0.0) + sprockets (2.2.2) + hike (~> 1.2) + multi_json (~> 1.0) + rack (~> 1.0) + tilt (~> 1.1, != 1.3.0) + sqlite3 (1.3.9) + thor (0.19.1) + tilt (1.4.1) + treetop (1.4.15) + polyglot + polyglot (>= 0.3.1) + tzinfo (0.3.41) + +PLATFORMS + ruby + +DEPENDENCIES + appraisal + rails (~> 3.2.19) + serialize_with_options! + shoulda + sqlite3 diff --git a/gemfiles/rails_40.gemfile b/gemfiles/rails_40.gemfile new file mode 100644 index 0000000..05fa813 --- /dev/null +++ b/gemfiles/rails_40.gemfile @@ -0,0 +1,7 @@ +# This file was generated by Appraisal + +source "http://rubygems.org" + +gem "rails", "~> 4.0.10" + +gemspec :path => "../" diff --git a/gemfiles/rails_40.gemfile.lock b/gemfiles/rails_40.gemfile.lock new file mode 100644 index 0000000..1237bc2 --- /dev/null +++ b/gemfiles/rails_40.gemfile.lock @@ -0,0 +1,94 @@ +PATH + remote: ../ + specs: + serialize_with_options (0.3.0) + activerecord (>= 3.0) + +GEM + remote: http://rubygems.org/ + specs: + actionmailer (4.0.10) + actionpack (= 4.0.10) + mail (~> 2.5, >= 2.5.4) + actionpack (4.0.10) + activesupport (= 4.0.10) + builder (~> 3.1.0) + erubis (~> 2.7.0) + rack (~> 1.5.2) + rack-test (~> 0.6.2) + activemodel (4.0.10) + activesupport (= 4.0.10) + builder (~> 3.1.0) + activerecord (4.0.10) + activemodel (= 4.0.10) + activerecord-deprecated_finders (~> 1.0.2) + activesupport (= 4.0.10) + arel (~> 4.0.0) + activerecord-deprecated_finders (1.0.3) + activesupport (4.0.10) + i18n (~> 0.6, >= 0.6.9) + minitest (~> 4.2) + multi_json (~> 1.3) + thread_safe (~> 0.1) + tzinfo (~> 0.3.37) + appraisal (1.0.2) + bundler + rake + thor (>= 0.14.0) + arel (4.0.2) + builder (3.1.4) + erubis (2.7.0) + hike (1.2.3) + i18n (0.6.11) + mail (2.6.1) + mime-types (>= 1.16, < 3) + mime-types (2.3) + minitest (4.7.5) + multi_json (1.10.1) + rack (1.5.2) + rack-test (0.6.2) + rack (>= 1.0) + rails (4.0.10) + actionmailer (= 4.0.10) + actionpack (= 4.0.10) + activerecord (= 4.0.10) + activesupport (= 4.0.10) + bundler (>= 1.3.0, < 2.0) + railties (= 4.0.10) + sprockets-rails (~> 2.0) + railties (4.0.10) + actionpack (= 4.0.10) + activesupport (= 4.0.10) + rake (>= 0.8.7) + thor (>= 0.18.1, < 2.0) + rake (10.3.2) + shoulda (3.5.0) + shoulda-context (~> 1.0, >= 1.0.1) + shoulda-matchers (>= 1.4.1, < 3.0) + shoulda-context (1.2.1) + shoulda-matchers (2.7.0) + activesupport (>= 3.0.0) + sprockets (2.12.2) + hike (~> 1.2) + multi_json (~> 1.0) + rack (~> 1.0) + tilt (~> 1.1, != 1.3.0) + sprockets-rails (2.1.4) + actionpack (>= 3.0) + activesupport (>= 3.0) + sprockets (~> 2.8) + sqlite3 (1.3.9) + thor (0.19.1) + thread_safe (0.3.4) + tilt (1.4.1) + tzinfo (0.3.41) + +PLATFORMS + ruby + +DEPENDENCIES + appraisal + rails (~> 4.0.10) + serialize_with_options! + shoulda + sqlite3 diff --git a/gemfiles/rails_41.gemfile b/gemfiles/rails_41.gemfile new file mode 100644 index 0000000..b5f7f28 --- /dev/null +++ b/gemfiles/rails_41.gemfile @@ -0,0 +1,7 @@ +# This file was generated by Appraisal + +source "http://rubygems.org" + +gem "rails", "~> 4.1.6" + +gemspec :path => "../" diff --git a/gemfiles/rails_41.gemfile.lock b/gemfiles/rails_41.gemfile.lock new file mode 100644 index 0000000..93401ff --- /dev/null +++ b/gemfiles/rails_41.gemfile.lock @@ -0,0 +1,100 @@ +PATH + remote: ../ + specs: + serialize_with_options (0.3.0) + activerecord (>= 3.0) + +GEM + remote: http://rubygems.org/ + specs: + actionmailer (4.1.6) + actionpack (= 4.1.6) + actionview (= 4.1.6) + mail (~> 2.5, >= 2.5.4) + actionpack (4.1.6) + actionview (= 4.1.6) + activesupport (= 4.1.6) + rack (~> 1.5.2) + rack-test (~> 0.6.2) + actionview (4.1.6) + activesupport (= 4.1.6) + builder (~> 3.1) + erubis (~> 2.7.0) + activemodel (4.1.6) + activesupport (= 4.1.6) + builder (~> 3.1) + activerecord (4.1.6) + activemodel (= 4.1.6) + activesupport (= 4.1.6) + arel (~> 5.0.0) + activesupport (4.1.6) + i18n (~> 0.6, >= 0.6.9) + json (~> 1.7, >= 1.7.7) + minitest (~> 5.1) + thread_safe (~> 0.1) + tzinfo (~> 1.1) + appraisal (1.0.2) + bundler + rake + thor (>= 0.14.0) + arel (5.0.1.20140414130214) + builder (3.2.2) + erubis (2.7.0) + hike (1.2.3) + i18n (0.6.11) + json (1.8.1) + mail (2.6.1) + mime-types (>= 1.16, < 3) + mime-types (2.3) + minitest (5.4.1) + multi_json (1.10.1) + rack (1.5.2) + rack-test (0.6.2) + rack (>= 1.0) + rails (4.1.6) + actionmailer (= 4.1.6) + actionpack (= 4.1.6) + actionview (= 4.1.6) + activemodel (= 4.1.6) + activerecord (= 4.1.6) + activesupport (= 4.1.6) + bundler (>= 1.3.0, < 2.0) + railties (= 4.1.6) + sprockets-rails (~> 2.0) + railties (4.1.6) + actionpack (= 4.1.6) + activesupport (= 4.1.6) + rake (>= 0.8.7) + thor (>= 0.18.1, < 2.0) + rake (10.3.2) + shoulda (3.5.0) + shoulda-context (~> 1.0, >= 1.0.1) + shoulda-matchers (>= 1.4.1, < 3.0) + shoulda-context (1.2.1) + shoulda-matchers (2.7.0) + activesupport (>= 3.0.0) + sprockets (2.12.2) + hike (~> 1.2) + multi_json (~> 1.0) + rack (~> 1.0) + tilt (~> 1.1, != 1.3.0) + sprockets-rails (2.1.4) + actionpack (>= 3.0) + activesupport (>= 3.0) + sprockets (~> 2.8) + sqlite3 (1.3.9) + thor (0.19.1) + thread_safe (0.3.4) + tilt (1.4.1) + tzinfo (1.2.2) + thread_safe (~> 0.1) + +PLATFORMS + ruby + +DEPENDENCIES + appraisal + rails (~> 4.1.6) + serialize_with_options! + shoulda + sqlite3 diff --git a/serialize_with_options.gemspec b/serialize_with_options.gemspec index 7931e21..c92b398 100644 --- a/serialize_with_options.gemspec +++ b/serialize_with_options.gemspec @@ -19,8 +19,9 @@ Gem::Specification.new do |s| s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } s.require_paths = ["lib"] - s.add_dependency "activerecord", "~> 4.0" + s.add_dependency "activerecord", ">= 3.0" s.add_development_dependency "shoulda" s.add_development_dependency "sqlite3" + s.add_development_dependency 'appraisal' end diff --git a/test/serialize_with_options_test.rb b/test/serialize_with_options_test.rb index f0cf186..eeb1279 100644 --- a/test/serialize_with_options_test.rb +++ b/test/serialize_with_options_test.rb @@ -78,7 +78,7 @@ class Review < ActiveRecord::Base end end -class SerializeWithOptionsTest < Minitest::Test +class SerializeWithOptionsTest < ActiveSupport::TestCase def self.should_serialize_with_options should "include active_record attributes" do assert_equal @user.name, @user_hash["name"] @@ -197,9 +197,16 @@ def self.should_serialize_with_options context 'passing options to the serializer' do setup do + if ActiveSupport::VERSION::MAJOR == 3 && ActiveSupport::VERSION::MINOR < 2 + ActiveRecord::Base.include_root_in_json = true + end @user_hash = @user.as_json(:with_email, :root => 'custom_root')['custom_root'] end - + + teardown do + ActiveRecord::Base.include_root_in_json = false + end + should "include active_record attributes" do assert_equal @user.name, @user_hash["name"] end diff --git a/test/test_helper.rb b/test/test_helper.rb index 0f06723..2d8d9a4 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -2,8 +2,31 @@ $:.unshift(File.dirname(__FILE__) + '/../lib') require 'rubygems' +require 'bundler' +begin + Bundler.setup(:default, :development) +rescue Bundler::BundlerError => e + $stderr.puts e.message + $stderr.puts "Run `bundle install` to install missing gems" + exit e.status_code +end + +require 'active_support/version' +if ActiveSupport::VERSION::MAJOR >= 4 + require 'minitest/autorun' +else + require 'test/unit' +end + +require 'sqlite3' require 'active_record' -require 'minitest/autorun' + +if ActiveSupport::VERSION::MAJOR == 3 + ActiveSupport.on_load(:active_record) do + self.include_root_in_json = false + end +end + require 'shoulda' require 'json' require 'serialize_with_options'