-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
233 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,3 +10,4 @@ | |
# rspec failure tracking | ||
.rspec_status | ||
*.gemfile.lock | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,105 @@ | ||
appraise "activerecord-6.0rc1" do | ||
gem "activerecord", "~>6.0.0.rc1", require: "active_record" | ||
|
||
platforms :jruby do | ||
gem "activerecord-jdbcsqlite3-adapter" | ||
gem "jdbc-sqlite3" | ||
gem "jdbc-postgres" | ||
end | ||
|
||
platforms :ruby, :mswin, :mingw do | ||
gem "pg", "~> 1.1.4" | ||
gem "sqlite3", "~> 1.4.0" | ||
end | ||
end | ||
|
||
appraise "activerecord-5.2" do | ||
gem "activerecord", "~>5.2", require: "active_record" | ||
|
||
gemfile.platforms :jruby do | ||
gem "activerecord-jdbcsqlite3-adapter" | ||
gem "jdbc-sqlite3" | ||
gem "jdbc-postgres" | ||
end | ||
|
||
gemfile.platforms :ruby, :mswin, :mingw do | ||
gem "sqlite3", "~> 1.3.0" | ||
gem "pg", "~> 0.21" | ||
end | ||
end | ||
|
||
appraise "activerecord-5.1" do | ||
gem "activerecord", "~>5.1", require: "active_record" | ||
|
||
gemfile.platforms :jruby do | ||
gem "activerecord-jdbcsqlite3-adapter" | ||
gem "jdbc-sqlite3" | ||
gem "jdbc-postgres" | ||
end | ||
|
||
gemfile.platforms :ruby, :mswin, :mingw do | ||
gem "sqlite3", "~> 1.3.0" | ||
gem "pg", "~> 0.21" | ||
end | ||
end | ||
|
||
appraise "activerecord-5.0" do | ||
gem "activerecord", "~>5.0", require: "active_record" | ||
|
||
gemfile.platforms :jruby do | ||
gem "activerecord-jdbcsqlite3-adapter" | ||
gem "jdbc-sqlite3" | ||
gem "jdbc-postgres" | ||
end | ||
|
||
gemfile.platforms :ruby, :mswin, :mingw do | ||
gem "sqlite3", "~> 1.3.0" | ||
gem "pg", "~> 0.21" | ||
end | ||
end | ||
|
||
appraise "activerecord-4.2" do | ||
gem "activerecord", "~>4.2", require: "active_record" | ||
|
||
gemfile.platforms :jruby do | ||
gem "activerecord-jdbcsqlite3-adapter" | ||
gem "jdbc-sqlite3" | ||
gem "jdbc-postgres" | ||
end | ||
|
||
gemfile.platforms :ruby, :mswin, :mingw do | ||
gem "sqlite3", "~> 1.3.0" | ||
gem "pg", "~> 0.21" | ||
end | ||
end | ||
|
||
appraise "activerecord-4.1" do | ||
gem "activerecord", "~>4.1", require: "active_record" | ||
|
||
gemfile.platforms :jruby do | ||
gem "activerecord-jdbcsqlite3-adapter" | ||
gem "jdbc-sqlite3" | ||
gem "jdbc-postgres" | ||
end | ||
|
||
gemfile.platforms :ruby, :mswin, :mingw do | ||
gem "sqlite3", "~> 1.3.0" | ||
gem "pg", "~> 0.21" | ||
end | ||
end | ||
|
||
appraise "activerecord-4.0" do | ||
gem "activerecord", "~>4.0", require: "active_record" | ||
|
||
gemfile.platforms :jruby do | ||
gem "activerecord-jdbcsqlite3-adapter" | ||
gem "jdbc-sqlite3" | ||
gem "jdbc-postgres" | ||
end | ||
|
||
gemfile.platforms :ruby, :mswin, :mingw do | ||
gem "sqlite3", "~> 1.3.0" | ||
gem "pg", "~> 0.21" | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
RSpec.describe "Integration with ActiveRecord" do | ||
before :each do | ||
define_db_schema do | ||
create_table(:parents) do |t| | ||
t.string :status | ||
t.timestamps null: false | ||
end | ||
|
||
create_table(:children) do |t| | ||
t.integer :parent_id | ||
t.timestamps null: false | ||
end | ||
end | ||
|
||
class Parent < ActiveRecord::Base | ||
has_many :children, -> { order(id: :desc) } | ||
end | ||
|
||
class Child < ActiveRecord::Base | ||
belongs_to :parent | ||
end | ||
end | ||
|
||
it "filters parents" do | ||
class MyFilter < ActionFilter::Base | ||
field :status | ||
end | ||
|
||
filter = MyFilter.new(status: "pending") | ||
|
||
expect(Parent.all.merge(filter).to_sql).to eq("SELECT \"parents\".* FROM \"parents\" WHERE \"parents\".\"status\" = 'pending'") | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
module SQLHelpers | ||
|
||
def connect_db | ||
# ActiveRecord::Base.logger = Logger.new(STDOUT) | ||
ActiveRecord::Base.logger = nil | ||
|
||
if ENV["DB"] == "sqlite" | ||
connect_sqlite | ||
elsif ENV["DB"] == "postgres" | ||
connect_postgres | ||
else | ||
raise StandardError, "database not supported, provide it in ENV['DB']. Supported versions are: 'sqlite' and 'postgres'." | ||
end | ||
end | ||
|
||
def define_db_schema(&block) | ||
connect_db | ||
ActiveRecord::Migration.verbose = false | ||
ActiveRecord::Schema.define(&block) | ||
end | ||
|
||
private | ||
|
||
def connect_sqlite | ||
ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ":memory:") | ||
end | ||
|
||
def connect_postgres | ||
ActiveRecord::Base.establish_connection(adapter: "postgresql", host: "localhost", | ||
database: "postgres", schema_search_path: "public") | ||
|
||
ActiveRecord::Base.connection.drop_database("action_filter_postgresql_spec") | ||
ActiveRecord::Base.connection.create_database("action_filter_postgresql_spec", | ||
encoding: "utf-8", adapter: "postgresql") | ||
|
||
ActiveRecord::Base.establish_connection(adapter: "postgresql", host: "localhost", | ||
database: "action_filter_postgresql_spec") | ||
end | ||
end |