Skip to content
Browse files

Checkout vendor/gems/scoped-search to make vmc works

  • Loading branch information...
1 parent 87344fc commit d6b0fde4193dafb2bbb3e4bb9b3bd072afd4a257 @tiendung tiendung committed
View
1 .gitignore
@@ -4,3 +4,4 @@ log/*.log
tmp/
config/mongoid.yml
*.swp
+.rvmrc
View
4 Gemfile
@@ -5,8 +5,8 @@ gem 'rails'
gem 'mongoid'
gem 'bson_ext'
-gem 'voteable_mongoid', :git => 'git://github.com/vinova/voteable_mongoid'
-gem 'scoped-search', :require => 'scoped_search', :git => 'git://github.com/vinova/scoped-search'
+gem 'voteable_mongoid'
+gem 'scoped-search', :require => 'scoped_search', :path => 'vendor/gems/scoped-search'
gem 'mongoid_slug', :require => 'mongoid/slug'
gem 'devise'
View
72 Gemfile.lock
@@ -1,26 +1,18 @@
-GIT
- remote: git://github.com/vinova/scoped-search
- revision: 694a5ea8be20920920127c4f99e19033bcdc26a3
+PATH
+ remote: vendor/gems/scoped-search
specs:
scoped-search (0.7.1)
-GIT
- remote: git://github.com/vinova/voteable_mongoid
- revision: 3e0b6a0f27bcf645b8489f553ad611b8d126f1ec
- specs:
- voteable_mongoid (0.7.2)
- mongoid (~> 2.0.0)
-
GEM
remote: http://rubygems.org/
specs:
abstract (1.0.0)
- actionmailer (3.0.6)
- actionpack (= 3.0.6)
+ actionmailer (3.0.7)
+ actionpack (= 3.0.7)
mail (~> 2.2.15)
- actionpack (3.0.6)
- activemodel (= 3.0.6)
- activesupport (= 3.0.6)
+ actionpack (3.0.7)
+ activemodel (= 3.0.7)
+ activesupport (= 3.0.7)
builder (~> 2.1.2)
erubis (~> 2.6.6)
i18n (~> 0.5.0)
@@ -28,27 +20,27 @@ GEM
rack-mount (~> 0.6.14)
rack-test (~> 0.5.7)
tzinfo (~> 0.3.23)
- activemodel (3.0.6)
- activesupport (= 3.0.6)
+ activemodel (3.0.7)
+ activesupport (= 3.0.7)
builder (~> 2.1.2)
i18n (~> 0.5.0)
- activerecord (3.0.6)
- activemodel (= 3.0.6)
- activesupport (= 3.0.6)
+ activerecord (3.0.7)
+ activemodel (= 3.0.7)
+ activesupport (= 3.0.7)
arel (~> 2.0.2)
tzinfo (~> 0.3.23)
- activeresource (3.0.6)
- activemodel (= 3.0.6)
- activesupport (= 3.0.6)
- activesupport (3.0.6)
+ activeresource (3.0.7)
+ activemodel (= 3.0.7)
+ activesupport (= 3.0.7)
+ activesupport (3.0.7)
arel (2.0.9)
bcrypt-ruby (2.1.4)
bson (1.3.0)
bson_ext (1.3.0)
builder (2.1.2)
- client_side_validations (3.0.2)
+ client_side_validations (3.0.4)
activesupport (~> 3.0.0)
- devise (1.2.1)
+ devise (1.3.3)
bcrypt-ruby (~> 2.1.2)
orm_adapter (~> 0.0.3)
warden (~> 1.0.3)
@@ -58,7 +50,7 @@ GEM
jquery-rails (0.2.7)
rails (~> 3.0)
thor (~> 0.14.4)
- mail (2.2.15)
+ mail (2.2.17)
activesupport (>= 2.3.6)
i18n (>= 0.4.0)
mime-types (~> 1.16)
@@ -71,7 +63,7 @@ GEM
mongo (~> 1.3)
tzinfo (~> 0.3.22)
will_paginate (~> 3.0.pre)
- mongoid_slug (0.7.1)
+ mongoid_slug (0.7.2)
mongoid (~> 2.0.0)
stringex (~> 1.2.0)
orm_adapter (0.0.4)
@@ -81,17 +73,17 @@ GEM
rack (>= 1.0.0)
rack-test (0.5.7)
rack (>= 1.0)
- rails (3.0.6)
- actionmailer (= 3.0.6)
- actionpack (= 3.0.6)
- activerecord (= 3.0.6)
- activeresource (= 3.0.6)
- activesupport (= 3.0.6)
+ rails (3.0.7)
+ actionmailer (= 3.0.7)
+ actionpack (= 3.0.7)
+ activerecord (= 3.0.7)
+ activeresource (= 3.0.7)
+ activesupport (= 3.0.7)
bundler (~> 1.0)
- railties (= 3.0.6)
- railties (3.0.6)
- actionpack (= 3.0.6)
- activesupport (= 3.0.6)
+ railties (= 3.0.7)
+ railties (3.0.7)
+ actionpack (= 3.0.7)
+ activesupport (= 3.0.7)
rake (>= 0.8.7)
thor (~> 0.14.4)
rake (0.8.7)
@@ -100,6 +92,8 @@ GEM
treetop (1.4.9)
polyglot (>= 0.3.1)
tzinfo (0.3.26)
+ voteable_mongoid (0.7.2)
+ mongoid (~> 2.0.0)
warden (1.0.3)
rack (>= 1.0.0)
will_paginate (3.0.pre2)
@@ -116,4 +110,4 @@ DEPENDENCIES
mongoid_slug
rails
scoped-search!
- voteable_mongoid!
+ voteable_mongoid
View
2 vendor/gems/scoped-search/.gitignore
@@ -0,0 +1,2 @@
+.bundle
+pkg
View
8 vendor/gems/scoped-search/Gemfile
@@ -0,0 +1,8 @@
+source :rubygems
+
+gem "rspec-rails", ">= 2.0.0.beta.17"
+gem 'jeweler'
+gem "rails", ">= 3.0.0.rc"
+gem "ruby-debug"
+
+gem 'sqlite3-ruby', :require => 'sqlite3'
View
109 vendor/gems/scoped-search/Gemfile.lock
@@ -0,0 +1,109 @@
+GEM
+ remote: http://rubygems.org/
+ specs:
+ abstract (1.0.0)
+ actionmailer (3.0.0.rc)
+ actionpack (= 3.0.0.rc)
+ mail (~> 2.2.5)
+ actionpack (3.0.0.rc)
+ activemodel (= 3.0.0.rc)
+ activesupport (= 3.0.0.rc)
+ builder (~> 2.1.2)
+ erubis (~> 2.6.6)
+ i18n (~> 0.4.1)
+ rack (~> 1.2.1)
+ rack-mount (~> 0.6.9)
+ rack-test (~> 0.5.4)
+ tzinfo (~> 0.3.22)
+ activemodel (3.0.0.rc)
+ activesupport (= 3.0.0.rc)
+ builder (~> 2.1.2)
+ i18n (~> 0.4.1)
+ activerecord (3.0.0.rc)
+ activemodel (= 3.0.0.rc)
+ activesupport (= 3.0.0.rc)
+ arel (~> 0.4.0)
+ tzinfo (~> 0.3.22)
+ activeresource (3.0.0.rc)
+ activemodel (= 3.0.0.rc)
+ activesupport (= 3.0.0.rc)
+ activesupport (3.0.0.rc)
+ arel (0.4.0)
+ activesupport (>= 3.0.0.beta)
+ builder (2.1.2)
+ columnize (0.3.1)
+ diff-lcs (1.1.2)
+ erubis (2.6.6)
+ abstract (>= 1.0.0)
+ gemcutter (0.6.1)
+ git (1.2.5)
+ i18n (0.4.1)
+ jeweler (1.4.0)
+ gemcutter (>= 0.1.0)
+ git (>= 1.2.5)
+ rubyforge (>= 2.0.0)
+ json_pure (1.4.3)
+ linecache (0.43)
+ mail (2.2.5)
+ activesupport (>= 2.3.6)
+ mime-types
+ treetop (>= 1.4.5)
+ mime-types (1.16)
+ nokogiri (1.4.2)
+ polyglot (0.3.1)
+ rack (1.2.1)
+ rack-mount (0.6.9)
+ rack (>= 1.0.0)
+ rack-test (0.5.4)
+ rack (>= 1.0)
+ rails (3.0.0.rc)
+ actionmailer (= 3.0.0.rc)
+ actionpack (= 3.0.0.rc)
+ activerecord (= 3.0.0.rc)
+ activeresource (= 3.0.0.rc)
+ activesupport (= 3.0.0.rc)
+ bundler (>= 1.0.0.rc.1)
+ railties (= 3.0.0.rc)
+ railties (3.0.0.rc)
+ actionpack (= 3.0.0.rc)
+ activesupport (= 3.0.0.rc)
+ rake (>= 0.8.3)
+ thor (~> 0.14.0)
+ rake (0.8.7)
+ rspec (2.0.0.beta.19)
+ rspec-core (= 2.0.0.beta.19)
+ rspec-expectations (= 2.0.0.beta.19)
+ rspec-mocks (= 2.0.0.beta.19)
+ rspec-core (2.0.0.beta.19)
+ rspec-expectations (2.0.0.beta.19)
+ diff-lcs (>= 1.1.2)
+ rspec-mocks (2.0.0.beta.19)
+ rspec-rails (2.0.0.beta.19)
+ rspec (= 2.0.0.beta.19)
+ webrat (>= 0.7.2.beta.1)
+ ruby-debug (0.10.3)
+ columnize (>= 0.1)
+ ruby-debug-base (~> 0.10.3.0)
+ ruby-debug-base (0.10.3)
+ linecache (>= 0.3)
+ rubyforge (2.0.4)
+ json_pure (>= 1.1.7)
+ sqlite3-ruby (1.3.1)
+ thor (0.14.0)
+ treetop (1.4.8)
+ polyglot (>= 0.3.1)
+ tzinfo (0.3.22)
+ webrat (0.7.2.beta.1)
+ nokogiri (>= 1.2.0)
+ rack (>= 1.0)
+ rack-test (>= 0.5.3)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ jeweler
+ rails (>= 3.0.0.rc)
+ rspec-rails (>= 2.0.0.beta.17)
+ ruby-debug
+ sqlite3-ruby
View
20 vendor/gems/scoped-search/LICENSE
@@ -0,0 +1,20 @@
+Copyright (c) 2010 Novagile, Written by Nicolas Blanco.
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
View
163 vendor/gems/scoped-search/README.textile
@@ -0,0 +1,163 @@
+h1. ScopedSearch
+
+ScopedSearch is a plugin to easily create search forms and do column ordering.
+It is written specifically for Rails 3 and is compatible with both ActiveRecord and "Mongoid":http://www.mongoid.org.
+
+ScopeSearch is Copyright (c) 2010 Novagile, written by "Nicolas Blanco":http://github.com/slainer68
+
+h2. Philosophy
+
+I've begun writing this plugin because I really like "Searchlogic":http://github.com/binarylogic/searchlogic from "Ben Johnson":http://www.binarylogic.com.
+I was using it in all my Rails 2 Active Record projects.
+
+Searchlogic has a feature that dynamically adds a lot of scopes in your models. But a feature from Searchlogic I really like is the ability to create an object
+that binds to your models scopes and being able to use it directly in a form. You can add many fields in your search forms, and the controller stays
+the same. I really wanted the same behaviour in Rails 3 and compatible with both ActiveRecord and Mongoid.
+
+h2. Installation
+
+For now, ScopedSearch is under development.
+You may use it as plugin or as a gem.
+
+**Gem**
+
+Edit your Gemfile and add :
+
+<pre>
+ gem 'scoped-search', :require => "scoped_search"
+</pre>
+
+**Plugin**
+
+<pre>
+ rails plugin install git://github.com/novagile/scoped-search.git
+</pre>
+
+ScopedSearch does not dynamically include itself in ActiveRecord or Mongoid, you have to include it in your models where you want to use it.
+
+Simply include the ScopedSearch::Model module in your models like this...
+
+<pre>
+ class Post < ActiveRecord::Base
+ include ScopedSearch::Model
+
+ scope :retrieve, lambda { |q| where("title like ?", "%#{q}%") }
+ scope :state_equals, lambda { |state| where( {:state => state }) }
+ scope :published, where(:published => true)
+ ...
+</pre>
+
+In your ApplicationHelper, include the ScopedSearch::Helpers module :
+
+<pre>
+ module ApplicationHelper
+ include ScopedSearch::Helpers
+ end
+</pre>
+
+h2. Console testing
+
+You can test the search object in a console!
+
+<pre>
+ > search = Post.scoped_search
+ => #<ScopedSearch::Base...>
+ > search.count
+ => 4
+ > search.all.map(&:body)
+ => ["test", "lalala", "foo", "bar"]
+ > search.retrieve = "foo"
+ => "foo"
+ > search.count
+ => 1
+ > search.all
+ => [#<Post id: 3, title: nil, body: "foo"...]
+</pre>
+
+h2. Usage
+
+Then in your controller you can do like this :
+
+<pre>
+ class PostsController < ApplicationController
+ def index
+ @search = Post.scoped_search(params[:search])
+ @posts = @search.all # or @search.paginate(...), or you can even continue the scope chain ! Just add your scopes like this : @search.build_relation.other_scope.other_other_scope... :)
+ ...
+</pre>
+
+In your view, you can create a form that takes your search object as parameter, like this :
+
+<pre>
+ <%= form_for @search do |f| %>
+ <%= f.text_field :retrieve %>
+ <%= f.select :state_equals, ["pending", "accepted", "deleted"] %>
+ <%= submit_tag "Search" %>
+ <% end %>
+</pre>
+
+h2. Column ordering
+
+You want to get column ordering for free? Sure!
+In your model, use the scoped_order method like this :
+
+<pre>
+ class Post < ActiveRecord::Base
+ ...
+ scoped_order :title, created_at, :updated_at # , ...
+ ...
+</pre>
+
+It will add two scopes for each column, named "ascend_by_column_name" and "descend_by_column_name" (like Searchlogic).
+
+Then in your views, you may use the order_for_scoped_search view helper like this :
+
+<pre>
+ <table>
+ <tr>
+ <th><%= link_to "Title", order_for_scoped_search(:title) %></th>
+ ...
+</pre>
+
+h2. Scopes with no arguments and excluded scopes
+
+If a scope attribute in the ScopedSearch object has a value that equals to "true", the scope will be chained without any parameters.
+If the scope attribute has a value that is blank? or equals to "false", the scope will be rejected and won't be chained in the search.
+
+Example :
+
+<pre>
+ search = User.scoped_search({ :accepted => "true", :rejected => "", :refused => "false", :has_email => ["foo@bar.com", "bar@foo.com"] })
+
+ search.all # => results in User.accepted.has_email(["foo@bar.com", "bar@foo.com"])
+</pre>
+
+h2. Issue with single Array attribute and multi parameters scopes
+
+When you define a scope, you may define it with a single value that accepts an array, or as a multi parameters scope.
+But I haven't found an easy way yet to know the number of parameters a scope accepts (if you know, please tell me!).
+So, for now, if you pass an array to a scoped attribute, it will be passed as an array to the scope.
+If you set attributename_multi_params to true, it will be passed as multiple params to the scope.
+
+Example :
+
+<pre>
+ class Post < ActiveRecord::Base
+ scope :retrieve_in_title_and_body, lambda { |a, b| where("title like ? and body like ?", "%#{a}%", "%#{b}") }
+ scope :retrieve_ids, lambda { |ids| where(:id => ids) }
+ end
+
+ # For a multi params scope
+ #
+ > search = Post.scoped_search
+ > search.retrieve_in_title_and_body = ["test", "whaaaa"]
+ > search.retrieve_in_title_and_body_multi_params = true
+
+ # For an Array param
+ > search.retrieve_ids = [1,2,3]
+</pre>
+
+h2. Notes
+
+This plugin is new and under development, patches and contributions are welcome! Please fork and make pull requests, thanks!
+
View
35 vendor/gems/scoped-search/Rakefile
@@ -0,0 +1,35 @@
+require "rake"
+require "rake/rdoctask"
+require "rspec"
+require "rspec/core/rake_task"
+
+begin
+ require 'jeweler'
+ Jeweler::Tasks.new do |gem|
+ gem.name = "scoped-search"
+ gem.summary = %Q{Easily implement search forms and column ordering based on your models scopes}
+ gem.description = %Q{Easily implement search forms and column ordering based on your models scopes. For Rails 3, compatible with ActiveRecord and Mongoid.}
+ gem.email = "slainer68@gmail.com"
+ gem.homepage = "http://github.com/novagile/scoped-search"
+ gem.authors = ["slainer68"]
+ gem.add_development_dependency "rspec", ">= 1.2.9"
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
+ end
+ Jeweler::GemcutterTasks.new
+rescue LoadError
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
+end
+
+Rspec::Core::RakeTask.new(:spec) do |spec|
+ spec.pattern = "spec/**/*_spec.rb"
+end
+
+Rake::RDocTask.new do |rdoc|
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
+
+ rdoc.rdoc_dir = 'rdoc'
+ rdoc.title = "scoped_search #{version}"
+ rdoc.rdoc_files.include('README*')
+ rdoc.rdoc_files.include('lib/**/*.rb')
+end
+
View
1 vendor/gems/scoped-search/VERSION
@@ -0,0 +1 @@
+0.7.1
View
2 vendor/gems/scoped-search/init.rb
@@ -0,0 +1,2 @@
+require "scoped_search"
+
View
121 vendor/gems/scoped-search/lib/scoped_search.rb
@@ -0,0 +1,121 @@
+# ScopedSearch, Copyright (c) 2010 Novagile.
+# Written by Nicolas Blanco.
+# Licensed under MIT license.
+#
+class ScopedSearch
+ class Base
+ extend ActiveModel::Naming
+
+ attr_reader :attributes, :model_class, :attributes_merged
+
+ def initialize(klass, options)
+ @model_class = klass
+ @attributes = options
+ @attributes_merged = @attributes.reverse_merge(klass.scopes.keys.inject({}) { |m,o| m[o] = nil; m; })
+
+ @attributes_merged.each do |attribute, value|
+ class_eval <<-RUBY
+ attr_accessor :#{attribute}_multi_params
+
+ def #{attribute}
+ @attributes[:#{attribute}]
+ end
+
+ def #{attribute}=(val)
+ @attributes[:#{attribute}] = val
+ end
+ RUBY
+ end
+ end
+
+ def build_relation
+ return model_class if attributes.empty?
+ attributes.reject { |k,v| v.blank? || v.to_s == "false" }.inject(model_class) do |s, k|
+ if model_class.scopes.keys.include?(k.first.to_sym)
+ if k.second.is_a?(Array) && multi_params?(k.first)
+ s.send(*k.flatten)
+ elsif k.second.to_s == "true"
+ s.send(k.first)
+ else
+ s.send(k.first, k.second)
+ end
+
+ else
+ s
+ end
+ end
+ end
+
+ def to_key; nil; end
+
+ def method_missing(method_name, *args)
+ build_relation.send(method_name, *args)
+ end
+
+ protected
+ def multi_params?(attribute)
+ send("#{attribute}_multi_params").present?
+ end
+ end
+
+ module Helpers
+ extend ActiveSupport::Concern
+
+ def form_for(record, *args, &block)
+ if record.is_a?(ScopedSearch::Base)
+ options = args.extract_options!
+ options.symbolize_keys!
+
+ default_model_route = (polymorphic_path(record.model_class) rescue nil)
+
+ options.reverse_merge!({ :url => default_model_route, :as => :search })
+ raise "You have to manually specify :url in your form_for options..." unless options[:url].present?
+
+ options[:html] ||= {}
+ options[:html].reverse_merge!({ :method => :get })
+ args << options
+ end
+
+ super(record, *args, &block)
+ end
+
+ # TODO :
+ # refactor this ?
+ def order_for_scoped_search(column, search_param = :search)
+ search_order = params[search_param].present? && params[search_param]["ascend_by_#{column}"].present? ? { "descend_by_#{column}" => true } : { "ascend_by_#{column}" => true }
+
+ params[search_param] ||= {}
+ search_without_order = params[search_param].clone
+ search_without_order.delete_if { |k,v| k.to_s.starts_with?("ascend_by") || k.to_s.starts_with?("descend_by") }
+
+ params.merge(search_param => search_without_order.merge(search_order))
+ end
+ end
+
+ module Model
+ extend ActiveSupport::Concern
+
+ module ClassMethods
+ def scoped_search(options={})
+ ScopedSearch::Base.new(self, options.present? ? options : {})
+ end
+
+ def scoped_order(*columns_names)
+ if defined?(Mongoid) && self.include?(Mongoid::Document)
+ columns_names.each do |column_name|
+ column_name = column_name.to_s
+ name = column_name.gsub('.', '_')
+ scope :"ascend_by_#{name}", order_by([column_name, :asc])
+ scope :"descend_by_#{name}", order_by([column_name, :desc])
+ end
+ else
+ columns_names.each do |column_name|
+ scope :"ascend_by_#{column_name}", order("#{column_name} asc")
+ scope :"descend_by_#{column_name}", order("#{column_name} desc")
+ end
+ end
+ end
+ end
+ end
+end
+
View
56 vendor/gems/scoped-search/scoped-search.gemspec
@@ -0,0 +1,56 @@
+# Generated by jeweler
+# DO NOT EDIT THIS FILE DIRECTLY
+# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
+# -*- encoding: utf-8 -*-
+
+Gem::Specification.new do |s|
+ s.name = %q{scoped-search}
+ s.version = "0.7.1"
+
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
+ s.authors = ["slainer68"]
+ s.date = %q{2010-09-14}
+ s.description = %q{Easily implement search forms and column ordering based on your models scopes. For Rails 3, compatible with ActiveRecord and Mongoid.}
+ s.email = %q{slainer68@gmail.com}
+ s.extra_rdoc_files = [
+ "LICENSE",
+ "README.textile"
+ ]
+ s.files = [
+ ".gitignore",
+ "Gemfile",
+ "Gemfile.lock",
+ "LICENSE",
+ "README.textile",
+ "Rakefile",
+ "VERSION",
+ "init.rb",
+ "lib/scoped_search.rb",
+ "scoped-search.gemspec",
+ "spec/scoped_search_spec.rb",
+ "spec/spec_helper.rb"
+ ]
+ s.homepage = %q{http://github.com/novagile/scoped-search}
+ s.rdoc_options = ["--charset=UTF-8"]
+ s.require_paths = ["lib"]
+ s.rubygems_version = %q{1.3.7}
+ s.summary = %q{Easily implement search forms and column ordering based on your models scopes}
+ s.test_files = [
+ "spec/scoped_search_spec.rb",
+ "spec/spec_helper.rb"
+ ]
+
+ if s.respond_to? :specification_version then
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
+ s.specification_version = 3
+
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
+ s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
+ else
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
+ end
+ else
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
+ end
+end
+
View
92 vendor/gems/scoped-search/spec/scoped_search_spec.rb
@@ -0,0 +1,92 @@
+require "spec_helper"
+
+%w(blahblah foo bar pipo waouhhh pipomolo).each do |title|
+ Post.create(:title => title, :body => "blah", :published => title.include?("pipo"))
+end
+
+Post.create(:title => "test multi params", :body => "this is to test multi params, whaaaa")
+
+describe 'ScopedSearch' do
+ it 'should respond to scoped_search and return a ScopedSearch::Base object' do
+ Post.should respond_to(:scoped_search)
+ Post.scoped_search.should be_a(ScopedSearch::Base)
+ end
+
+ it 'should have the same count when initializing an empty search' do
+ Post.count.should == 7
+
+ @search = Post.scoped_search
+ @search.count.should == 7
+ end
+
+ describe 'initialization' do
+ it 'should be possible to initialize without a hash and change attributes later' do
+ @search = Post.scoped_search
+ @search.attributes.should == {}
+
+ @search.retrieve = "pipo"
+ @search.published = true
+ @search.attributes.should have(2).elements
+ @search.attributes[:retrieve].should == "pipo"
+ @search.attributes[:published].should == true
+ end
+
+ it 'should be possible to initialize with a hash' do
+ @search = Post.scoped_search({ :retrieve => "pipo", :published => true })
+ @search.attributes.should have(2).elements
+
+ @search.retrieve.should == "pipo"
+ @search.published.should == true
+ end
+ end
+
+ describe 'searching' do
+ it 'should be possible to search with one parameter' do
+ @search = Post.scoped_search({ :retrieve => "foo" })
+ @search.retrieve.should == "foo"
+ @search.count.should == 1
+
+ @search.all.should have(1).element
+ @search.retrieve = nil
+ @search.count.should == 7
+ end
+
+ it 'should be possible to search with multiple parameters' do
+ @search = Post.scoped_search({ :retrieve => "foo", :published => true })
+ @search.retrieve.should == "foo"
+ @search.published.should == true
+ @search.count.should == 0
+
+ @search.all.should have(0).element
+ @search.retrieve = nil
+ @search.count.should == 2
+ @search.all.should have(2).elements
+ end
+
+ it 'should be possible to search in a multi params scope' do
+ @search = Post.scoped_search
+
+ @search.retrieve_in_title_and_body = ["test", "whaaaa"]
+ @search.retrieve_in_title_and_body_multi_params = true
+ @search.count.should == 1
+
+ @search = Post.scoped_search({ :retrieve_in_title_and_body => ["test", "whaaaa"], :retrieve_in_title_and_body_multi_params => "true" })
+ @search.count.should == 1
+ end
+
+ it 'should be possible to search in a scope that wants an Array' do
+ @search = Post.scoped_search
+
+ @search.retrieve_ids = ["3", "4"]
+ @search.count.should == 2
+
+ @search = Post.scoped_search({ :retrieve_ids => ["3", "4"] })
+ @search.count.should == 2
+ end
+ end
+
+ it 'should be possible to build the relation' do
+ @search = Post.scoped_search({ :retrieve => "foo" })
+ @search.build_relation.should be_a(ActiveRecord::Relation)
+ end
+end
View
34 vendor/gems/scoped-search/spec/spec_helper.rb
@@ -0,0 +1,34 @@
+require 'ruby-debug'
+require 'rspec'
+
+require "active_record"
+
+ActiveRecord::Schema.verbose = false
+ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
+
+ActiveRecord::Base.configurations = true
+ActiveRecord::Schema.define(:version => 1) do
+ create_table :posts do |t|
+ t.string :title
+ t.text :body
+ t.boolean :published
+
+ t.timestamps
+ end
+end
+
+require File.dirname(__FILE__) + '/../lib/scoped_search'
+
+class Post < ActiveRecord::Base
+ include ScopedSearch::Model
+
+ scope :published, where(:published => true)
+ scope :retrieve, lambda { |q| where("title like ?", "%#{q}%") }
+ scope :retrieve_in_title_and_body, lambda { |a,b| where("title like ? and body like ?", "%#{a}%", "%#{b}") }
+ scope :retrieve_ids, lambda { |ids| where(:id => ids) }
+end
+
+RSpec.configure do |config|
+ config.mock_with :rspec
+end
+

0 comments on commit d6b0fde

Please sign in to comment.
Something went wrong with that request. Please try again.