Skip to content

Commit

Permalink
Travis CI
Browse files Browse the repository at this point in the history
  • Loading branch information
voltechs committed May 10, 2017
1 parent f54a798 commit 2d41942
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 15 deletions.
17 changes: 15 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
sudo: false
language: ruby
sudo: false
rvm:
- 2.0
- 2.1
- 2.2
- 2.3.1
before_install: gem install bundler -v 1.13.6
- 2.4.0
cache: bundler
script:
- bundle exec rspec
services:
- postgresql
addons:
postgresql: "9.1"
env:
- RSPEC_VERSION="<2.99"
- RSPEC_VERSION="~>3.0
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ Deleting data is never good. A common solution is to use `default_scope`, but co

DeletedAt leverages the power of SQL views to achieve the same effect. It also takes advantage of Ruby's flexibility.

## Requirements

`DeletedAt` requires PostgreSQL 9.1+ and Ruby 2.0.0+ (as the `pg` gem requires Ruby 2.0.0).

## Installation

Add this line to your application's Gemfile:
Expand Down
11 changes: 5 additions & 6 deletions deleted_at.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,14 @@ Gem::Specification.new do |spec|
spec.bindir = "exe"
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ["lib"]
spec.required_ruby_version = '>= 2.0'

rails_versions = ['>= 4.1', '< 5']
spec.required_ruby_version = '>= 2.0.0'

spec.add_runtime_dependency 'pg', '~> 0'
spec.add_runtime_dependency "activerecord", "~> 4.2"
spec.add_runtime_dependency "railties", "~> 4.2"
spec.add_runtime_dependency "scenic", "~> 1.3"
spec.add_runtime_dependency 'request_store', '~> 1.1', '>= 1.1'
spec.add_runtime_dependency "activerecord", rails_versions

spec.add_development_dependency "bundler", "~> 1.13"
spec.add_development_dependency "bundler", "~> 1.3"
spec.add_development_dependency "rake", "~> 10.0"
spec.add_development_dependency "rspec", "~> 3.0"
spec.add_development_dependency "pry", "~> 0.10"
Expand Down
5 changes: 4 additions & 1 deletion lib/deleted_at.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
require "deleted_at/version"
require 'deleted_at/railtie'
require 'deleted_at/views'
require 'deleted_at/active_record/base'
require 'deleted_at/active_record/relation'

require 'deleted_at/railtie' if defined?(Rails::Railtie)

module DeletedAt

Expand Down
3 changes: 1 addition & 2 deletions lib/deleted_at/active_record/base.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
require 'active_record'
require 'deleted_at/views'
require 'deleted_at/active_record/relation'
require 'active_support'

module DeletedAt
module ActiveRecord
Expand Down
2 changes: 0 additions & 2 deletions lib/deleted_at/railtie.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
require 'rails/railtie'
require 'deleted_at/active_record/base'
require 'deleted_at/active_record/relation'

module DeletedAt
class Railtie < Rails::Railtie
Expand Down
14 changes: 12 additions & 2 deletions lib/deleted_at/views.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def self.all_table_exists?(model)
WHERE table_name = '#{all_table(model)}'
);
SQL
query.first['exists'] == 't'
get_truthy_value_from_psql(query)
end

def self.deleted_view_exists?(model)
Expand All @@ -41,7 +41,7 @@ def self.deleted_view_exists?(model)
WHERE table_name = '#{deleted_view(model)}'
);
SQL
query.first['exists'] == 't'
get_truthy_value_from_psql(query)
end

def self.present_view(model)
Expand All @@ -68,5 +68,15 @@ def self.uninstall_present_view(model)
def self.uninstall_deleted_view(model)
model.connection.execute("DROP VIEW IF EXISTS \"#{deleted_view(model)}\"")
end

private

def self.get_truthy_value_from_psql(result)
# Some versions of PSQL return {"?column?"=>"t"}
# instead of {"first"=>"t"}, so we're saying screw it,
# just give me the first value of whatever is returned
result.try(:first).try(:values).try(:first) == 't'
end

end
end

0 comments on commit 2d41942

Please sign in to comment.