-
Notifications
You must be signed in to change notification settings - Fork 14
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
169 additions
and
17 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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
language: ruby | ||
rvm: | ||
- 2.1.5 | ||
- 2.2.3 | ||
before_install: gem install bundler -v 1.10.3 |
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 |
---|---|---|
|
@@ -104,7 +104,6 @@ def expr(expr) | |
end | ||
|
||
def search | ||
p @parameters | ||
@client.search(@parameters) | ||
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,8 @@ | ||
class CreatePosts < ActiveRecord::Migration | ||
def change | ||
create_table :posts do |t| | ||
t.string :content | ||
t.datetime :created_at | ||
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
require 'spec_helper' | ||
|
||
describe Nazrin::ActiveRecord::Searchable do | ||
let!(:post) { Post.create(content: 'content', created_at: Time.now) } | ||
|
||
it { expect(Post).to be_respond_to :search } | ||
it { expect(Post).to be_respond_to :fields } | ||
it { expect(Post).to be_respond_to :field } | ||
it { expect(post).to be_respond_to :add_to_index } | ||
it { expect(post).to be_respond_to :update_in_index } | ||
it { expect(post).to be_respond_to :delete_from_index } | ||
|
||
describe '#search' do | ||
before { allow_any_instance_of(Nazrin::SearchClient).to receive(:search).and_return(FakeResponse.new) } | ||
|
||
it { expect(Post.search.is_a?(Nazrin::SearchClient)).to eq true } | ||
it { expect(Post.search.data_accessor.is_a?(Nazrin::ActiveRecord::DataAccessor)).to eq true } | ||
|
||
it { expect(Post.search.size(1).start(0).execute).to eq [post] } | ||
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
require 'spec_helper' | ||
|
||
describe Nazrin::DocumentClient do | ||
let(:document_client) { described_class.new } | ||
it { expect(document_client).to be_respond_to :client } | ||
it { expect(document_client.client.class).to eq Aws::CloudSearchDomain::Client } | ||
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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
require 'spec_helper' | ||
|
||
describe Nazrin do | ||
describe 'configure' do | ||
let(:config) { Nazrin.config } | ||
it { expect(config.debug_mode).to be false } | ||
it { expect(config.search_endpoint).to eq 'http://search' } | ||
it { expect(config.document_endpoint).to eq 'http://document' } | ||
it { expect(config.region).to eq :region } | ||
it { expect(config.access_key_id).to eq :access_key_id } | ||
it { expect(config.secret_access_key).to eq :secret_access_key } | ||
it { expect(config.pagination).to eq 'kaminari' } | ||
end | ||
|
||
describe 'paginated_array' do | ||
let(:paginated_array) do | ||
Nazrin.paginated_array( | ||
[1, 2, 3], | ||
current_page: 1, per_page: 1, total_count: 3) | ||
end | ||
|
||
context 'kaminari' do | ||
before { Nazrin.config.pagination = 'kaminari' } | ||
it { expect(paginated_array.class).to eq Kaminari::PaginatableArray } | ||
end | ||
|
||
context 'nazrin' do | ||
before { Nazrin.config.pagination = 'nazrin' } | ||
it { expect(paginated_array.class).to eq Nazrin::PaginatedArray } | ||
it { expect(paginated_array.first_page?).to eq true } | ||
it { expect(paginated_array.last_page?).to eq false } | ||
it { expect(paginated_array.total_pages).to eq 3 } | ||
it { expect(paginated_array.previous_page).to eq nil } | ||
it { expect(paginated_array.next_page).to eq 2 } | ||
it { expect(paginated_array.out_of_bounds?).to eq false } | ||
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
require 'spec_helper' | ||
|
||
describe Nazrin::SearchClient do | ||
let(:search_client) { described_class.new } | ||
it { expect(search_client).to be_respond_to :parameters } | ||
it { expect(search_client).to be_respond_to :data_accessor } | ||
|
||
describe '#execute' do | ||
before { allow_any_instance_of(Nazrin::SearchClient).to receive(:search).and_return(FakeResponse.new) } | ||
|
||
it { expect(search_client.execute.is_a?(FakeResponse)).to eq true } | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
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,2 +1,76 @@ | ||
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__) | ||
|
||
require 'coveralls' | ||
Coveralls.wear! | ||
|
||
require 'kaminari' | ||
require 'aws-sdk' | ||
require 'active_record' | ||
require 'nazrin' | ||
|
||
Kaminari::Hooks.init | ||
|
||
Nazrin.configure do |config| | ||
config.debug_mode = false | ||
config.search_endpoint = 'http://search' | ||
config.document_endpoint = 'http://document' | ||
config.region = :region | ||
config.access_key_id = :access_key_id | ||
config.secret_access_key = :secret_access_key | ||
config.pagination = 'kaminari' | ||
end | ||
|
||
class FakeResponse | ||
def data | ||
self | ||
end | ||
|
||
def hits | ||
self | ||
end | ||
|
||
def hit | ||
[self] | ||
end | ||
|
||
def id | ||
1 | ||
end | ||
|
||
def found | ||
1 | ||
end | ||
end | ||
|
||
ActiveRecord::Base.establish_connection( | ||
adapter: 'sqlite3', | ||
database: ':memory:') | ||
|
||
class Post < ActiveRecord::Base | ||
include Nazrin::ActiveRecord::Searchable | ||
|
||
searchable do | ||
fields [:content] | ||
field(:created_at) { created_at.utc.iso8601 } | ||
end | ||
end | ||
|
||
ActiveRecord::Migration.verbose = false | ||
ActiveRecord::Migrator.migrate File.expand_path('../db/migrate', __FILE__), nil | ||
|
||
require 'database_cleaner' | ||
|
||
RSpec.configure do |config| | ||
config.before(:suite) do | ||
DatabaseCleaner.strategy = :transaction | ||
DatabaseCleaner.clean_with(:truncation) | ||
end | ||
|
||
config.before(:each) do | ||
DatabaseCleaner.start | ||
end | ||
|
||
config.after(:each) do | ||
DatabaseCleaner.clean | ||
end | ||
end |