From 69a2125f0451a757052e1bb50866657b407cf0eb Mon Sep 17 00:00:00 2001 From: pyromaniac Date: Sat, 2 May 2015 14:49:56 +0300 Subject: [PATCH] Appraisals + all the rails gemfiles init --- .rspec | 1 - .rvmrc | 2 +- .travis.yml | 14 +++- Appraisals | 7 ++ Gemfile | 4 - Guardfile | 83 +++++++++++++++---- README.md | 2 - active_data.gemspec | 5 +- gemfiles/Gemfile.rails-3.2 | 15 ---- gemfiles/Gemfile.rails-4.0 | 15 ---- gemfiles/rails.3.2.gemfile | 14 ++++ gemfiles/rails.4.0.gemfile | 14 ++++ gemfiles/rails.4.1.gemfile | 14 ++++ gemfiles/rails.4.2.gemfile | 14 ++++ lib/active_data.rb | 3 +- lib/active_data/active_record/associations.rb | 6 +- .../model/associations/reflections/base.rb | 5 ++ spec/lib/active_data/model/lifecycle_spec.rb | 4 +- spec/spec_helper.rb | 5 +- 19 files changed, 162 insertions(+), 65 deletions(-) create mode 100644 Appraisals delete mode 100644 gemfiles/Gemfile.rails-3.2 delete mode 100644 gemfiles/Gemfile.rails-4.0 create mode 100644 gemfiles/rails.3.2.gemfile create mode 100644 gemfiles/rails.4.0.gemfile create mode 100644 gemfiles/rails.4.1.gemfile create mode 100644 gemfiles/rails.4.2.gemfile diff --git a/.rspec b/.rspec index 2ac585b..616c433 100644 --- a/.rspec +++ b/.rspec @@ -1,3 +1,2 @@ --colour --backtrace ---order random diff --git a/.rvmrc b/.rvmrc index b0e4367..2d41486 100644 --- a/.rvmrc +++ b/.rvmrc @@ -1 +1 @@ -rvm use --create 2.0.0@active_data +rvm use --create 2.1.5@active_data diff --git a/.travis.yml b/.travis.yml index 07a3f95..93a905c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,9 +1,17 @@ rvm: - 1.9.3 - 2.0.0 + - 2.1.5 + - 2.2.0 - rbx gemfile: - - Gemfile - - gemfiles/Gemfile.rails-3.2 - - gemfiles/Gemfile.rails-4.0 + - gemfiles/rails.3.2.gemfile + - gemfiles/rails.4.0.gemfile + - gemfiles/rails.4.1.gemfile + - gemfiles/rails.4.2.gemfile + +matrix: + exclude: + - rvm: 2.2.0 + gemfile: gemfiles/rails.3.2.gemfile diff --git a/Appraisals b/Appraisals new file mode 100644 index 0000000..80df17e --- /dev/null +++ b/Appraisals @@ -0,0 +1,7 @@ +%w(3.2 4.0 4.1 4.2).each do |version| + appraise "rails.#{version}" do + gem 'activesupport', "~> #{version}.0" + gem 'activemodel', "~> #{version}.0" + gem 'activerecord', "~> #{version}.0" + end +end diff --git a/Gemfile b/Gemfile index eb4a518..976ecdb 100644 --- a/Gemfile +++ b/Gemfile @@ -1,12 +1,8 @@ source 'https://rubygems.org' -# Specify your gem's dependencies in active_data.gemspec gemspec group :test do gem 'guard' gem 'guard-rspec' - gem 'rb-inotify', require: false - gem 'rb-fsevent', require: false - gem 'rb-fchange', require: false end diff --git a/Guardfile b/Guardfile index f855df0..5dad7fa 100644 --- a/Guardfile +++ b/Guardfile @@ -1,24 +1,77 @@ # A sample Guardfile # More info at https://github.com/guard/guard#readme -guard :rspec do - watch(%r{^spec/.+_spec\.rb$}) - watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" } - watch('spec/spec_helper.rb') { "spec" } - - # Rails example - watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" } - watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" } - watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] } - watch(%r{^spec/support/(.+)\.rb$}) { "spec" } - watch('config/routes.rb') { "spec/routing" } - watch('app/controllers/application_controller.rb') { "spec/controllers" } +## Uncomment and set this to only include directories you want to watch +# directories %w(app lib config test spec features) + +## Uncomment to clear the screen before every task +# clearing :on + +## Guard internally checks for changes in the Guardfile and exits. +## If you want Guard to automatically start up again, run guard in a +## shell loop, e.g.: +## +## $ while bundle exec guard; do echo "Restarting Guard..."; done +## +## Note: if you are using the `directories` clause above and you are not +## watching the project directory ('.'), then you will want to move +## the Guardfile to a watched dir and symlink it back, e.g. +# +# $ mkdir config +# $ mv Guardfile config/ +# $ ln -s config/Guardfile . +# +# and, you'll have to watch "config/Guardfile" instead of "Guardfile" + +# Note: The cmd option is now required due to the increasing number of ways +# rspec may be run, below are examples of the most common uses. +# * bundler: 'bundle exec rspec' +# * bundler binstubs: 'bin/rspec' +# * spring: 'bin/rspec' (This will use spring if running and you have +# installed the spring binstubs per the docs) +# * zeus: 'zeus rspec' (requires the server to be started separately) +# * 'just' rspec: 'rspec' + +guard :rspec, cmd: "bundle exec rspec" do + require "guard/rspec/dsl" + dsl = Guard::RSpec::Dsl.new(self) + + # Feel free to open issues for suggestions and improvements + + # RSpec files + rspec = dsl.rspec + watch(rspec.spec_helper) { rspec.spec_dir } + watch(rspec.spec_support) { rspec.spec_dir } + watch(rspec.spec_files) + + # Ruby files + ruby = dsl.ruby + dsl.watch_spec_files_for(ruby.lib_files) + + # Rails files + rails = dsl.rails(view_extensions: %w(erb haml slim)) + dsl.watch_spec_files_for(rails.app_files) + dsl.watch_spec_files_for(rails.views) + + watch(rails.controllers) do |m| + [ + rspec.spec.("routing/#{m[1]}_routing"), + rspec.spec.("controllers/#{m[1]}_controller"), + rspec.spec.("acceptance/#{m[1]}") + ] + end + + # Rails config changes + watch(rails.spec_helper) { rspec.spec_dir } + watch(rails.routes) { "#{rspec.spec_dir}/routing" } + watch(rails.app_controller) { "#{rspec.spec_dir}/controllers" } # Capybara features specs - watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/features/#{m[1]}_spec.rb" } + watch(rails.view_dirs) { |m| rspec.spec.("features/#{m[1]}") } # Turnip features and steps watch(%r{^spec/acceptance/(.+)\.feature$}) - watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' } + watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) do |m| + Dir[File.join("**/#{m[1]}.feature")][0] || "spec/acceptance" + end end - diff --git a/README.md b/README.md index bb80d65..638b357 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,5 @@ [![Build Status](https://travis-ci.org/pyromaniac/active_data.png?branch=master)](https://travis-ci.org/pyromaniac/active_data) [![Code Climate](https://codeclimate.com/github/pyromaniac/active_data.png)](https://codeclimate.com/github/pyromaniac/active_data) -[![Coverage Status](https://coveralls.io/repos/pyromaniac/active_data/badge.png?branch=master)](https://coveralls.io/r/pyromaniac/active_data?branch=master) - # ActiveData diff --git a/active_data.gemspec b/active_data.gemspec index d0f3c44..0f42889 100644 --- a/active_data.gemspec +++ b/active_data.gemspec @@ -16,10 +16,11 @@ Gem::Specification.new do |gem| gem.version = ActiveData::VERSION gem.add_development_dependency 'rake' + gem.add_development_dependency 'appraisal' gem.add_development_dependency 'rspec' + gem.add_development_dependency 'rspec-its' gem.add_development_dependency 'rubysl', '~> 2.0' if RUBY_ENGINE == 'rbx' - gem.add_development_dependency 'coveralls' - gem.add_development_dependency 'sqlite3', '1.3.8' + gem.add_development_dependency 'sqlite3' gem.add_development_dependency 'database_cleaner' gem.add_development_dependency 'activerecord', '>= 3.2' gem.add_development_dependency 'uuidtools' diff --git a/gemfiles/Gemfile.rails-3.2 b/gemfiles/Gemfile.rails-3.2 deleted file mode 100644 index 752be71..0000000 --- a/gemfiles/Gemfile.rails-3.2 +++ /dev/null @@ -1,15 +0,0 @@ -source "http://rubygems.org" - -gemspec path: '../' - -gem 'activerecord', '~> 3.2.0' -gem 'activesupport', '~> 3.2.0' -gem 'activemodel', '~> 3.2.0' - -group :test do - gem 'guard' - gem 'guard-rspec' - gem 'rb-inotify', require: false - gem 'rb-fsevent', require: false - gem 'rb-fchange', require: false -end diff --git a/gemfiles/Gemfile.rails-4.0 b/gemfiles/Gemfile.rails-4.0 deleted file mode 100644 index 0c51d14..0000000 --- a/gemfiles/Gemfile.rails-4.0 +++ /dev/null @@ -1,15 +0,0 @@ -source "http://rubygems.org" - -gemspec path: '../' - -gem 'activerecord', '~> 4.0.0' -gem 'activesupport', '~> 4.0.0' -gem 'activemodel', '~> 4.0.0' - -group :test do - gem 'guard' - gem 'guard-rspec' - gem 'rb-inotify', require: false - gem 'rb-fsevent', require: false - gem 'rb-fchange', require: false -end diff --git a/gemfiles/rails.3.2.gemfile b/gemfiles/rails.3.2.gemfile new file mode 100644 index 0000000..c69a172 --- /dev/null +++ b/gemfiles/rails.3.2.gemfile @@ -0,0 +1,14 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "activesupport", "~> 3.2.0" +gem "activemodel", "~> 3.2.0" +gem "activerecord", "~> 3.2.0" + +group :test do + gem "guard" + gem "guard-rspec" +end + +gemspec :path => "../" diff --git a/gemfiles/rails.4.0.gemfile b/gemfiles/rails.4.0.gemfile new file mode 100644 index 0000000..9580791 --- /dev/null +++ b/gemfiles/rails.4.0.gemfile @@ -0,0 +1,14 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "activesupport", "~> 4.0.0" +gem "activemodel", "~> 4.0.0" +gem "activerecord", "~> 4.0.0" + +group :test do + gem "guard" + gem "guard-rspec" +end + +gemspec :path => "../" diff --git a/gemfiles/rails.4.1.gemfile b/gemfiles/rails.4.1.gemfile new file mode 100644 index 0000000..a4f70cb --- /dev/null +++ b/gemfiles/rails.4.1.gemfile @@ -0,0 +1,14 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "activesupport", "~> 4.1.0" +gem "activemodel", "~> 4.1.0" +gem "activerecord", "~> 4.1.0" + +group :test do + gem "guard" + gem "guard-rspec" +end + +gemspec :path => "../" diff --git a/gemfiles/rails.4.2.gemfile b/gemfiles/rails.4.2.gemfile new file mode 100644 index 0000000..a406dbe --- /dev/null +++ b/gemfiles/rails.4.2.gemfile @@ -0,0 +1,14 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "activesupport", "~> 4.2.0" +gem "activemodel", "~> 4.2.0" +gem "activerecord", "~> 4.2.0" + +group :test do + gem "guard" + gem "guard-rspec" +end + +gemspec :path => "../" diff --git a/lib/active_data.rb b/lib/active_data.rb index e636d4e..fa9a749 100644 --- a/lib/active_data.rb +++ b/lib/active_data.rb @@ -1,6 +1,7 @@ require 'active_support' -require 'active_support/concern' +require 'active_support/deprecation' require 'active_support/core_ext' +require 'active_support/concern' require 'singleton' require 'active_model' diff --git a/lib/active_data/active_record/associations.rb b/lib/active_data/active_record/associations.rb index f296d8d..7b5d5eb 100644 --- a/lib/active_data/active_record/associations.rb +++ b/lib/active_data/active_record/associations.rb @@ -30,7 +30,11 @@ def is_a? klass } )) reflection.define_methods self - self.reflections = reflections.merge(reflection.name => reflection) + if ::ActiveRecord::Reflection.respond_to? :add_reflection + ::ActiveRecord::Reflection.add_reflection self, reflection.name, reflection + else + self.reflections = reflections.merge(reflection.name => reflection) + end callback_name = "update_#{reflection.name}_association" before_save callback_name diff --git a/lib/active_data/model/associations/reflections/base.rb b/lib/active_data/model/associations/reflections/base.rb index 7254f87..15a0b5c 100644 --- a/lib/active_data/model/associations/reflections/base.rb +++ b/lib/active_data/model/associations/reflections/base.rb @@ -7,6 +7,7 @@ class Base WRITE = ->(reflection, object, value) { object.write_attribute reflection.name, value } attr_reader :name, :options + attr_accessor :parent_reflection def initialize name, options = {} @name, @options = name.to_sym, options @@ -24,6 +25,10 @@ def validate? false end + def belongs_to? + false + end + def class_name @class_name ||= (options[:class_name].presence || name.to_s.classify).to_s end diff --git a/spec/lib/active_data/model/lifecycle_spec.rb b/spec/lib/active_data/model/lifecycle_spec.rb index 9f509e5..cb8fd37 100644 --- a/spec/lib/active_data/model/lifecycle_spec.rb +++ b/spec/lib/active_data/model/lifecycle_spec.rb @@ -111,8 +111,8 @@ def append action specify { expect { subject.destroy }.to raise_error ActiveData::UndestroyableObject } specify { expect { subject.destroy! }.to raise_error ActiveData::UndestroyableObject } - specify { subject.destroy { true }.should be_true } - specify { subject.destroy! { true }.should be_true } + specify { subject.destroy { true }.should be_a User } + specify { subject.destroy! { true }.should be_a User } context 'instance performer' do before { subject.define_save { false } } diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 260d27e..5c16b02 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,9 +1,7 @@ require 'bundler' Bundler.require -require 'coveralls' -Coveralls.wear! - +require 'rspec/its' require 'active_record' require 'database_cleaner' @@ -22,6 +20,7 @@ RSpec.configure do |config| config.mock_with :rspec + config.order = :random config.include ModelHelpers