This repository has been archived by the owner on Dec 19, 2022. It is now read-only.
forked from activerecord-hackery/ransack
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add spec described in activerecord-hackery#1153.
- Loading branch information
Showing
2 changed files
with
91 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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
require 'spec_helper' | ||
|
||
module Ransack | ||
describe Search do | ||
describe '#ransack' do | ||
context 'parameters provided in a harmonious order' do | ||
it 'produces the expected result' do | ||
result = ProviderCalendar. | ||
ransack({ "account_email_cont" => "account1", "user_email_eq" => "[email protected]" }). | ||
result. | ||
map(&:provider_id) | ||
|
||
expect(result).to eq(["[email protected]", "[email protected]"]) | ||
end | ||
end | ||
|
||
context 'parameters provided in a disharmonious order' do | ||
it 'produces the expected result' do | ||
result = ProviderCalendar. | ||
ransack({ "user_email_eq" => "[email protected]", "account_email_cont" => "account1" }). | ||
result. | ||
map(&:provider_id) | ||
|
||
expect(result).to eq(["[email protected]", "[email protected]"]) | ||
end | ||
end | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -178,6 +178,34 @@ class Note < ActiveRecord::Base | |
belongs_to :notable, polymorphic: true | ||
end | ||
|
||
class User < ActiveRecord::Base | ||
has_many :accounts, | ||
class_name: "ProviderAccount" | ||
has_many :contacts, | ||
class_name: "ProviderContact", | ||
through: :accounts, | ||
source: :contacts | ||
has_many :calendars, | ||
class_name: "ProviderCalendar", | ||
through: :accounts, | ||
source: :calendars | ||
end | ||
|
||
class ProviderAccount < ActiveRecord::Base | ||
belongs_to :user | ||
|
||
has_many :calendars, class_name: "ProviderCalendar" | ||
end | ||
|
||
class ProviderCalendar < ActiveRecord::Base | ||
belongs_to :account, | ||
class_name: "ProviderAccount", | ||
foreign_key: "provider_account_id", | ||
inverse_of: :calendars | ||
|
||
has_one :user, through: :account | ||
end | ||
|
||
module Schema | ||
def self.create | ||
ActiveRecord::Migration.verbose = false | ||
|
@@ -236,6 +264,25 @@ def self.create | |
t.integer :target_person_id | ||
t.integer :article_id | ||
end | ||
|
||
create_table "users", force: :cascade do |t| | ||
t.string "email", default: "", null: false | ||
t.index ["email"], name: "idx_users_on_email", unique: true | ||
end | ||
|
||
create_table "provider_accounts", force: :cascade do |t| | ||
t.bigint "user_id", null: false | ||
t.string "email", null: false | ||
t.index ["email"], name: "idx_p_accounts_on_email" | ||
t.index ["user_id"], name: "idx_p_accounts_on_user_id" | ||
end | ||
|
||
create_table "provider_calendars", force: :cascade do |t| | ||
t.bigint "provider_account_id", null: false | ||
t.string "provider_id", null: false | ||
t.index ["provider_account_id", "provider_id"], name: "idx_p_calendars_on_p_account_id_and_p_id", unique: true | ||
t.index ["provider_account_id"], name: "idx_p_calendars_on_p_account_id" | ||
end | ||
end | ||
|
||
10.times do | ||
|
@@ -257,6 +304,21 @@ def self.create | |
body: 'First post!', | ||
article: Article.make(title: 'Hello, world!') | ||
) | ||
|
||
user1 = User.create!(email: "[email protected]") | ||
user2 = User.create!(email: "[email protected]") | ||
user1_acct1 = ProviderAccount.create!(user: user1, email: "[email protected]") | ||
user1_acct2 = ProviderAccount.create!(user: user1, email: "[email protected]") | ||
user2_acct1 = ProviderAccount.create!(user: user2, email: "[email protected]") | ||
user2_acct2 = ProviderAccount.create!(user: user2, email: "[email protected]") | ||
ProviderCalendar.create!(account: user1_acct1, provider_id: "[email protected]") | ||
ProviderCalendar.create!(account: user1_acct1, provider_id: "[email protected]") | ||
ProviderCalendar.create!(account: user1_acct2, provider_id: "[email protected]") | ||
ProviderCalendar.create!(account: user1_acct2, provider_id: "[email protected]") | ||
ProviderCalendar.create!(account: user2_acct1, provider_id: "[email protected]") | ||
ProviderCalendar.create!(account: user2_acct1, provider_id: "[email protected]") | ||
ProviderCalendar.create!(account: user2_acct2, provider_id: "[email protected]") | ||
ProviderCalendar.create!(account: user2_acct2, provider_id: "[email protected]") | ||
end | ||
end | ||
|
||
|