Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/Arcath/Adauth
- Loading branch information
Showing
8 changed files
with
100 additions
and
27 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,7 +1,7 @@ | ||
PATH | ||
remote: . | ||
specs: | ||
adauth (2.0.1) | ||
adauth (2.0.2) | ||
expects (~> 0.0.2) | ||
net-ldap | ||
|
||
|
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,18 @@ | ||
module Adauth | ||
class SearchResults < Array | ||
def limit(x) | ||
return self[0..(x-1)] | ||
end | ||
|
||
def order(field, direction = :asc) | ||
case direction | ||
when :asc | ||
return sort! { |x, y| x.send(field) <=> y.send(field) } | ||
when :desc | ||
return order(field, :asc).reverse! | ||
else | ||
raise "Invalid Order Provided, please use :asc or :desc" | ||
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
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,41 @@ | ||
require 'spec_helper' | ||
|
||
describe Adauth::SearchResults, :no_ad => true do | ||
let(:test_array) do | ||
[OpenStruct.new({name: "foo"}), OpenStruct.new({name: "bar"}), OpenStruct.new({name: "widget"})] | ||
end | ||
|
||
let(:sorted_array) do | ||
[OpenStruct.new({name: "bar"}), OpenStruct.new({name: "foo"}), OpenStruct.new({name: "widget"})] | ||
end | ||
|
||
let(:search_results) do | ||
Adauth::SearchResults.new(test_array) | ||
end | ||
|
||
it "should create self from_array" do | ||
Adauth::SearchResults.new(test_array).should be_a Adauth::SearchResults | ||
end | ||
|
||
it "should have the limit function" do | ||
search_results.limit(2).length.should eq 2 | ||
search_results.limit(2).last.should_not eq test_array.last | ||
search_results.limit(2).should be_a Adauth::SearchResults | ||
end | ||
|
||
it "should have the order function" do | ||
search_results.order(:name, :asc).should eq sorted_array | ||
search_results.order(:name, :asc).should be_a Adauth::SearchResults | ||
search_results.order(:name, :desc).should eq sorted_array.reverse | ||
search_results.order(:name, :desc).should be_a Adauth::SearchResults | ||
end | ||
|
||
it "should handle having a wrong direction passed to it" do | ||
lambda { search_results.order(:name, :foo) }.should raise_exception | ||
end | ||
|
||
it "should default to :asc for order" do | ||
search_results.order(:name).should eq sorted_array | ||
search_results.order(:name).should be_a Adauth::SearchResults | ||
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