event_calendar_engine 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile +23 -0
- data/Gemfile.lock +161 -0
- data/README +1 -0
- data/Rakefile +39 -0
- data/VERSION +1 -0
- data/app/controllers/application_controller.rb +4 -0
- data/app/controllers/attendees_controller.rb +53 -0
- data/app/controllers/event_calendar/application_controller.rb +5 -0
- data/app/controllers/event_revisions_controller.rb +26 -0
- data/app/controllers/events_controller.rb +129 -0
- data/app/helpers/event_calendar/application_helper.rb +118 -0
- data/app/helpers/events_helper.rb +2 -0
- data/app/models/attendee.rb +6 -0
- data/app/models/deletable_instance_methods.rb +7 -0
- data/app/models/event.rb +124 -0
- data/app/models/event_revision.rb +9 -0
- data/app/models/participant.rb +23 -0
- data/app/models/participator.rb +20 -0
- data/app/views/attendees/index.html.erb +14 -0
- data/app/views/attendees/new.html.erb +13 -0
- data/app/views/event-calendar-shared/_flash.html.erb +7 -0
- data/app/views/event-calendar-shared/_main_menu.html.erb +3 -0
- data/app/views/event-calendar-shared/_navigation.html.erb +15 -0
- data/app/views/event_revisions/index.html.erb +31 -0
- data/app/views/event_revisions/show.html.erb +5 -0
- data/app/views/events/_browse_event_revisions.html.erb +19 -0
- data/app/views/events/_event.html.erb +10 -0
- data/app/views/events/_event_details.html.erb +26 -0
- data/app/views/events/_form.html.erb +36 -0
- data/app/views/events/attendees.html.erb +29 -0
- data/app/views/events/edit.html.erb +3 -0
- data/app/views/events/index.html.erb +41 -0
- data/app/views/events/new.html.erb +3 -0
- data/app/views/events/search.html.erb +11 -0
- data/app/views/events/show.html.erb +30 -0
- data/app/views/layouts/application.html.erb +49 -0
- data/config/application.rb +42 -0
- data/config/blueprint_settings.yml +10 -0
- data/config/boot.rb +13 -0
- data/config/cucumber.yml +8 -0
- data/config/database.example.yml +22 -0
- data/config/environment.rb +5 -0
- data/config/environments/development.rb +26 -0
- data/config/environments/production.rb +49 -0
- data/config/environments/test.rb +38 -0
- data/config/initializers/backtrace_silencers.rb +7 -0
- data/config/initializers/formtastic.rb +55 -0
- data/config/initializers/inflections.rb +10 -0
- data/config/initializers/mime_types.rb +5 -0
- data/config/initializers/secret_token.rb +9 -0
- data/config/initializers/session_store.rb +10 -0
- data/config/locales/en.yml +5 -0
- data/config/routes.rb +67 -0
- data/db/migrate/20101011142543_create_events.rb +19 -0
- data/db/migrate/20101011172027_create_attendees.rb +16 -0
- data/db/migrate/20101011200048_make_events_revisable.rb +25 -0
- data/db/schema.rb +45 -0
- data/db/seeds.rb +7 -0
- data/lib/event_calendar.rb +3 -0
- data/lib/event_calendar/engine.rb +25 -0
- data/lib/generators/event_calendar/install/USAGE +5 -0
- data/lib/generators/event_calendar/install/install_generator.rb +19 -0
- data/lib/generators/event_calendar/install/templates/event_calendar.rake +169 -0
- data/lib/tasks/blueprint.rake +25 -0
- data/lib/tasks/cucumber.rake +53 -0
- data/public/404.html +26 -0
- data/public/422.html +26 -0
- data/public/500.html +26 -0
- data/public/favicon.ico +0 -0
- data/public/images/rails.png +0 -0
- data/public/javascripts/event_calendar.js +62 -0
- data/public/javascripts/event_calendar_behaviors.js +131 -0
- data/public/javascripts/fullcalendar.js +3965 -0
- data/public/javascripts/jquery-ui-1.7.2.custom.min.js +298 -0
- data/public/javascripts/jquery.clonePosition.js +27 -0
- data/public/javascripts/jquery.js +154 -0
- data/public/javascripts/jquery.qtip-1.0.0-rc3.js +2149 -0
- data/public/javascripts/jquery.string.1.0-min.js +6 -0
- data/public/javascripts/jquery.tablesorter.min.js +2 -0
- data/public/javascripts/lowpro.jquery.js +224 -0
- data/public/javascripts/rails.js +132 -0
- data/public/robots.txt +5 -0
- data/public/stylesheets/blueprint/grid.css +280 -0
- data/public/stylesheets/blueprint/icons/cross.png +0 -0
- data/public/stylesheets/blueprint/icons/doc.png +0 -0
- data/public/stylesheets/blueprint/icons/email.png +0 -0
- data/public/stylesheets/blueprint/icons/external.png +0 -0
- data/public/stylesheets/blueprint/icons/feed.png +0 -0
- data/public/stylesheets/blueprint/icons/im.png +0 -0
- data/public/stylesheets/blueprint/icons/key.png +0 -0
- data/public/stylesheets/blueprint/icons/pdf.png +0 -0
- data/public/stylesheets/blueprint/icons/tick.png +0 -0
- data/public/stylesheets/blueprint/icons/visited.png +0 -0
- data/public/stylesheets/blueprint/icons/xls.png +0 -0
- data/public/stylesheets/blueprint/ie.css +36 -0
- data/public/stylesheets/blueprint/plugins/buttons/icons/cross.png +0 -0
- data/public/stylesheets/blueprint/plugins/buttons/icons/key.png +0 -0
- data/public/stylesheets/blueprint/plugins/buttons/icons/tick.png +0 -0
- data/public/stylesheets/blueprint/plugins/buttons/readme.txt +32 -0
- data/public/stylesheets/blueprint/plugins/buttons/screen.css +97 -0
- data/public/stylesheets/blueprint/plugins/fancy-type/readme.txt +14 -0
- data/public/stylesheets/blueprint/plugins/fancy-type/screen.css +71 -0
- data/public/stylesheets/blueprint/plugins/link-icons/icons/doc.png +0 -0
- data/public/stylesheets/blueprint/plugins/link-icons/icons/email.png +0 -0
- data/public/stylesheets/blueprint/plugins/link-icons/icons/external.png +0 -0
- data/public/stylesheets/blueprint/plugins/link-icons/icons/feed.png +0 -0
- data/public/stylesheets/blueprint/plugins/link-icons/icons/im.png +0 -0
- data/public/stylesheets/blueprint/plugins/link-icons/icons/pdf.png +0 -0
- data/public/stylesheets/blueprint/plugins/link-icons/icons/visited.png +0 -0
- data/public/stylesheets/blueprint/plugins/link-icons/icons/xls.png +0 -0
- data/public/stylesheets/blueprint/plugins/link-icons/readme.txt +18 -0
- data/public/stylesheets/blueprint/plugins/link-icons/screen.css +40 -0
- data/public/stylesheets/blueprint/plugins/rtl/readme.txt +10 -0
- data/public/stylesheets/blueprint/plugins/rtl/screen.css +110 -0
- data/public/stylesheets/blueprint/plugins/silksprite/sprite.css +1 -0
- data/public/stylesheets/blueprint/plugins/silksprite/sprites.png +0 -0
- data/public/stylesheets/blueprint/print.css +29 -0
- data/public/stylesheets/blueprint/readme.txt +12 -0
- data/public/stylesheets/blueprint/screen.css +429 -0
- data/public/stylesheets/error_messages.css +65 -0
- data/public/stylesheets/formtastic.css +131 -0
- data/public/stylesheets/formtastic_changes.css +14 -0
- data/public/stylesheets/fullcalendar.css +574 -0
- data/public/stylesheets/fullcalendar_changes.css +0 -0
- data/public/stylesheets/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
- data/public/stylesheets/smoothness/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
- data/public/stylesheets/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
- data/public/stylesheets/smoothness/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
- data/public/stylesheets/smoothness/images/ui-bg_glass_75_dadada_1x400.png +0 -0
- data/public/stylesheets/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
- data/public/stylesheets/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
- data/public/stylesheets/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
- data/public/stylesheets/smoothness/images/ui-icons_222222_256x240.png +0 -0
- data/public/stylesheets/smoothness/images/ui-icons_2e83ff_256x240.png +0 -0
- data/public/stylesheets/smoothness/images/ui-icons_454545_256x240.png +0 -0
- data/public/stylesheets/smoothness/images/ui-icons_888888_256x240.png +0 -0
- data/public/stylesheets/smoothness/images/ui-icons_cd0a0a_256x240.png +0 -0
- data/public/stylesheets/smoothness/jquery-ui-1.7.2.custom.css +406 -0
- data/public/stylesheets/tablesorter/blue/asc.gif +0 -0
- data/public/stylesheets/tablesorter/blue/bg.gif +0 -0
- data/public/stylesheets/tablesorter/blue/desc.gif +0 -0
- data/public/stylesheets/tablesorter/blue/style.css +39 -0
- data/public/stylesheets/text_and_colors.css +49 -0
- data/spec/controllers/attendees_controller_spec.rb +27 -0
- data/spec/controllers/event_revisions_controller_spec.rb +86 -0
- data/spec/controllers/events_controller_spec.rb +168 -0
- data/spec/fixtures/event_calendar_events.yml +8 -0
- data/spec/models/deletable_instance_methods_spec.rb +61 -0
- data/spec/models/event_revision_spec.rb +36 -0
- data/spec/models/event_spec.rb +139 -0
- data/spec/spec_helper.rb +27 -0
- data/spec/spec_helpers/mocks.rb +6 -0
- data/vendor/plugins/searchable_by/MIT-LICENSE +20 -0
- data/vendor/plugins/searchable_by/README +55 -0
- data/vendor/plugins/searchable_by/Rakefile +23 -0
- data/vendor/plugins/searchable_by/init.rb +2 -0
- data/vendor/plugins/searchable_by/install.rb +1 -0
- data/vendor/plugins/searchable_by/lib/searchable_by.rb +137 -0
- data/vendor/plugins/searchable_by/tasks/searchable_by_tasks.rake +4 -0
- data/vendor/plugins/searchable_by/test/boot.rb +21 -0
- data/vendor/plugins/searchable_by/test/database.yml +22 -0
- data/vendor/plugins/searchable_by/test/fixtures/companies.yml +10 -0
- data/vendor/plugins/searchable_by/test/fixtures/company.rb +5 -0
- data/vendor/plugins/searchable_by/test/fixtures/employee.rb +5 -0
- data/vendor/plugins/searchable_by/test/fixtures/employees.yml +28 -0
- data/vendor/plugins/searchable_by/test/fixtures/schema.rb +18 -0
- data/vendor/plugins/searchable_by/test/helper.rb +12 -0
- data/vendor/plugins/searchable_by/test/lib/activerecord_test_case.rb +43 -0
- data/vendor/plugins/searchable_by/test/lib/activerecord_test_connector.rb +75 -0
- data/vendor/plugins/searchable_by/test/lib/load_fixtures.rb +9 -0
- data/vendor/plugins/searchable_by/test/searchable_by_test.rb +73 -0
- data/vendor/plugins/searchable_by/uninstall.rb +1 -0
- metadata +606 -0
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# This file is copied to spec/ when you run 'rails generate rspec:install'
|
2
|
+
ENV["RAILS_ENV"] ||= 'test'
|
3
|
+
require File.expand_path("../../config/environment", __FILE__)
|
4
|
+
require 'rspec/rails'
|
5
|
+
|
6
|
+
# Requires supporting ruby files with custom matchers and macros, etc,
|
7
|
+
# in spec/support/ and its subdirectories.
|
8
|
+
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
# == Mock Framework
|
12
|
+
#
|
13
|
+
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
|
14
|
+
#
|
15
|
+
# config.mock_with :mocha
|
16
|
+
# config.mock_with :flexmock
|
17
|
+
# config.mock_with :rr
|
18
|
+
config.mock_with :rspec
|
19
|
+
|
20
|
+
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
|
21
|
+
config.fixture_path = "#{::Rails.root}/spec/fixtures"
|
22
|
+
|
23
|
+
# If you're not using ActiveRecord, or you'd prefer not to run each of your
|
24
|
+
# examples within a transaction, remove the following line or assign false
|
25
|
+
# instead of true.
|
26
|
+
config.use_transactional_fixtures = true
|
27
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 [name of plugin creator]
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@@ -0,0 +1,55 @@
|
|
1
|
+
SearchableBy
|
2
|
+
============
|
3
|
+
|
4
|
+
Adds a search method to query your ActiveRecord models:
|
5
|
+
|
6
|
+
searchable_by :field_a, :field_b, :field_etc
|
7
|
+
|
8
|
+
YourModel.search 'some search words'
|
9
|
+
|
10
|
+
Examples
|
11
|
+
========
|
12
|
+
|
13
|
+
# declare with searchable_by
|
14
|
+
class User < ActiveRecord::Base
|
15
|
+
enables the "search" method and by default searches 'login' and 'email' columns
|
16
|
+
searchable_by :login, :email
|
17
|
+
end
|
18
|
+
|
19
|
+
# search into associations
|
20
|
+
class User < ActiveRecord::Base
|
21
|
+
has_many :addresses
|
22
|
+
searchable_by :login, :email, :addresses => [:street, :city]
|
23
|
+
end
|
24
|
+
|
25
|
+
# simple search - based on default fields in searchable_by line
|
26
|
+
User.search 'fred'
|
27
|
+
=> [#<User>, #<User>]
|
28
|
+
|
29
|
+
# specify which fields to search on with :narrow_fields
|
30
|
+
User.search 'fred', :narrow_fields => [:email, :login, :name]
|
31
|
+
=> [#<User>, #<User>, #<User>]
|
32
|
+
|
33
|
+
# use default search fields but pass other options
|
34
|
+
User.search 'fred', :conditions => { :is_admin => true }, :limit => 2
|
35
|
+
=> [#<User>, #<User>]
|
36
|
+
|
37
|
+
# use :page option and we'll assume that you want to paginate using will_paginate
|
38
|
+
User.search 'j', :page => 2
|
39
|
+
=> [#<User>, #<User>, #<User>, #<User>, #<User>]
|
40
|
+
|
41
|
+
# by default, all search words must be found
|
42
|
+
User.search 'fred john jack susan'
|
43
|
+
=> []
|
44
|
+
|
45
|
+
# set :require_all to false if you want to do an "OR" search
|
46
|
+
User.search 'fred john jack susan', :require_all => false
|
47
|
+
=> [#<User>, #<User>, #<User>, #<User>, #<User>]
|
48
|
+
|
49
|
+
# use double quotes to identify phrases
|
50
|
+
User.search '"fred flintstone"', :narrow_fields => [:login, :full_name]
|
51
|
+
=> [#<User>]
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
Copyright (c) 2008-2009 Jason LaPier, released under the MIT license
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/testtask'
|
3
|
+
require 'rake/rdoctask'
|
4
|
+
|
5
|
+
desc 'Default: run unit tests.'
|
6
|
+
task :default => :test
|
7
|
+
|
8
|
+
desc 'Test the searchable_by plugin.'
|
9
|
+
Rake::TestTask.new(:test) do |t|
|
10
|
+
t.libs << 'lib'
|
11
|
+
t.libs << 'test'
|
12
|
+
t.pattern = 'test/**/*_test.rb'
|
13
|
+
t.verbose = true
|
14
|
+
end
|
15
|
+
|
16
|
+
desc 'Generate documentation for the searchable_by plugin.'
|
17
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
18
|
+
rdoc.rdoc_dir = 'rdoc'
|
19
|
+
rdoc.title = 'SearchableBy'
|
20
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
21
|
+
rdoc.rdoc_files.include('README')
|
22
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
23
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
# Install hook code here
|
@@ -0,0 +1,137 @@
|
|
1
|
+
# Adds a search method to query your ActiveRecord models
|
2
|
+
#
|
3
|
+
# # declare with searchable_by
|
4
|
+
# class User < ActiveRecord::Base
|
5
|
+
# # enables the "search" method and by default searches 'login' and 'email' columns
|
6
|
+
# searchable_by :login, :email
|
7
|
+
# end
|
8
|
+
#
|
9
|
+
# # search into associations
|
10
|
+
# class User < ActiveRecord::Base
|
11
|
+
# has_many :addresses
|
12
|
+
# searchable_by :user => [:login, :email], :addresses => [:street, :city]
|
13
|
+
# end
|
14
|
+
#
|
15
|
+
# simple search - based on default fields in searchable_by line
|
16
|
+
# User.search 'fred'
|
17
|
+
# => [#<User>, #<User>]
|
18
|
+
#
|
19
|
+
# # specify which fields to search on with :narrow_fields
|
20
|
+
# User.search 'fred', :narrow_fields => [:email, :login, :name]
|
21
|
+
# => [#<User>, #<User>, #<User>]
|
22
|
+
#
|
23
|
+
# # use default search fields but pass other options
|
24
|
+
# User.search 'fred', :conditions => { :is_admin => true }, :limit => 2
|
25
|
+
# => [#<User>, #<User>]
|
26
|
+
#
|
27
|
+
# # use :page option and we'll assume that you want to paginate using will_paginate
|
28
|
+
# User.search 'j', :page => 2
|
29
|
+
# => [#<User>, #<User>, #<User>, #<User>, #<User>]
|
30
|
+
#
|
31
|
+
# # by default, all search words must be found
|
32
|
+
# User.search 'fred john jack susan'
|
33
|
+
# => []
|
34
|
+
#
|
35
|
+
# # set :require_all to false if you want to do an "OR" search
|
36
|
+
# User.search 'fred john jack susan', :require_all => false
|
37
|
+
# => [#<User>, #<User>, #<User>, #<User>, #<User>]
|
38
|
+
#
|
39
|
+
# # use double quotes to identify phrases
|
40
|
+
# User.search '"fred flintstone"', :narrow_fields => [:login, :full_name]
|
41
|
+
# => [#<User>]
|
42
|
+
#
|
43
|
+
|
44
|
+
module Offtheline
|
45
|
+
module SearchableBy
|
46
|
+
def self.included(klass)
|
47
|
+
klass.extend ClassMethods
|
48
|
+
end
|
49
|
+
|
50
|
+
module ClassMethods
|
51
|
+
def searchable_by(*tables_and_columns)
|
52
|
+
@search_tables_and_columns = make_hash_from_cols_and_tables(tables_and_columns)
|
53
|
+
end
|
54
|
+
|
55
|
+
def search_tables_and_columns
|
56
|
+
@search_tables_and_columns
|
57
|
+
end
|
58
|
+
|
59
|
+
# in addition to other find options, there is an option to
|
60
|
+
# :require_all keywords or phrases (true by default) and an option
|
61
|
+
# :narrow_fields to change the fields you want to search from the default specified in searchable_by
|
62
|
+
def search(query, options = {})
|
63
|
+
cols_with_tables = options[:narrow_fields] ? make_hash_from_cols_and_tables(options[:narrow_fields]) : @search_tables_and_columns
|
64
|
+
options[:require_all] = true if options[:require_all].nil?
|
65
|
+
|
66
|
+
with_scope :find => { :conditions => search_conditions(query, options[:require_all], cols_with_tables),
|
67
|
+
:include => cols_with_tables.keys.reject{|k| k == table_name.to_sym } } do
|
68
|
+
# strip out 'search' specific options
|
69
|
+
search_options = options.reject { |k,v| [:require_all, :narrow_fields].include? k.to_sym }
|
70
|
+
if options.include?(:page)
|
71
|
+
# I think this will help us fail if will_paginate is not installed
|
72
|
+
gem 'mislav-will_paginate'
|
73
|
+
# take out require_all option when calling paginate
|
74
|
+
paginate :all, search_options
|
75
|
+
else
|
76
|
+
# take out require_all option when calling find
|
77
|
+
find :all, search_options
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
private
|
83
|
+
|
84
|
+
def make_hash_from_cols_and_tables(tables_and_columns)
|
85
|
+
tables_and_columns = [tables_and_columns].flatten
|
86
|
+
hash_of_tables_and_columns = { table_name.to_sym => [] }
|
87
|
+
tables_and_columns.each do |table_or_column|
|
88
|
+
if table_or_column.is_a? Hash
|
89
|
+
hash_of_tables_and_columns.merge! table_or_column
|
90
|
+
else
|
91
|
+
hash_of_tables_and_columns[table_name.to_sym] << table_or_column
|
92
|
+
end
|
93
|
+
end
|
94
|
+
hash_of_tables_and_columns
|
95
|
+
end
|
96
|
+
|
97
|
+
def search_conditions(query, require_all, cols_with_tables=nil )
|
98
|
+
return nil if query.blank?
|
99
|
+
cols_with_tables ||= @search_tables_and_columns
|
100
|
+
|
101
|
+
# pull out "quoted phrases" - this regular expression will find all matches of phrases
|
102
|
+
# that start and end with a double-quote
|
103
|
+
phrases = query.scan(/\"\w+[^\"]*\w+\"/)
|
104
|
+
unless phrases.empty?
|
105
|
+
# replace the phrase with an empty string
|
106
|
+
phrases.each { |phrase| query.gsub! phrase, '' }
|
107
|
+
# take the quotes out of the phrase
|
108
|
+
phrases = phrases.map { |ph| ph.gsub("\"", '') }
|
109
|
+
end
|
110
|
+
|
111
|
+
# note how we split keywords by commas and spaces, just in case
|
112
|
+
words = query.split(",").map(&:split).flatten
|
113
|
+
|
114
|
+
# the uniq takes care of any dupes
|
115
|
+
words_and_phrases = (words + phrases).uniq
|
116
|
+
|
117
|
+
binds = {} # bind symbols
|
118
|
+
or_frags = [] # OR fragments
|
119
|
+
cnt = 1 # to keep count on the symbols and OR fragments
|
120
|
+
|
121
|
+
# create 'conditions' parts for each word
|
122
|
+
for word_or_phrase in words_and_phrases
|
123
|
+
# generate our little SQL bites for each field that we want to check for the keyword
|
124
|
+
like_frags = cols_with_tables.map { |table,fields|
|
125
|
+
[fields].flatten.map { |f| "#{table.to_s.tableize}.#{f} LIKE :word#{cnt}" } }.flatten
|
126
|
+
or_frags << "(#{like_frags.join(" OR " )})"
|
127
|
+
binds["word#{cnt}".to_sym] = "%#{word_or_phrase.to_s.downcase}%"
|
128
|
+
cnt += 1
|
129
|
+
end
|
130
|
+
|
131
|
+
# return the OR fragments joined by ANDs (if require_all) or ORs
|
132
|
+
# and the named bind variables
|
133
|
+
[or_frags.join(require_all ? " AND " : " OR " ), binds]
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
plugin_root = File.join(File.dirname(__FILE__), '..')
|
2
|
+
version = ENV['RAILS_VERSION']
|
3
|
+
version = nil if version and version == ""
|
4
|
+
|
5
|
+
# first look for a symlink to a copy of the framework
|
6
|
+
if !version and framework_root = ["#{plugin_root}/rails", "#{plugin_root}/../../rails"].find { |p| File.directory? p }
|
7
|
+
puts "found framework root: #{framework_root}"
|
8
|
+
# this allows for a plugin to be tested outside of an app and without Rails gems
|
9
|
+
$:.unshift "#{framework_root}/activesupport/lib", "#{framework_root}/activerecord/lib", "#{framework_root}/actionpack/lib"
|
10
|
+
else
|
11
|
+
# simply use installed gems if available
|
12
|
+
puts "using Rails#{version ? ' ' + version : nil} gems"
|
13
|
+
require 'rubygems'
|
14
|
+
|
15
|
+
if version
|
16
|
+
gem 'rails', version
|
17
|
+
else
|
18
|
+
gem 'actionpack'
|
19
|
+
gem 'activerecord'
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
sqlite3:
|
2
|
+
database: ":memory:"
|
3
|
+
adapter: sqlite3
|
4
|
+
timeout: 500
|
5
|
+
|
6
|
+
sqlite2:
|
7
|
+
database: ":memory:"
|
8
|
+
adapter: sqlite2
|
9
|
+
|
10
|
+
mysql:
|
11
|
+
adapter: mysql
|
12
|
+
username: root
|
13
|
+
password:
|
14
|
+
encoding: utf8
|
15
|
+
database: will_paginate_unittest
|
16
|
+
|
17
|
+
postgres:
|
18
|
+
adapter: postgresql
|
19
|
+
username: mislav
|
20
|
+
password:
|
21
|
+
database: will_paginate_unittest
|
22
|
+
min_messages: warning
|
@@ -0,0 +1,28 @@
|
|
1
|
+
fry:
|
2
|
+
first_name: Philip
|
3
|
+
last_name: Fry
|
4
|
+
occupation: Delivery Boy
|
5
|
+
company_id: 1
|
6
|
+
created_at: <%= 1.day.ago.to_s(:db) %>
|
7
|
+
updated_at:
|
8
|
+
leela:
|
9
|
+
first_name: Turanga
|
10
|
+
last_name: Leela
|
11
|
+
occupation: Captain
|
12
|
+
company_id: 1
|
13
|
+
created_at: <%= 1.day.ago.to_s(:db) %>
|
14
|
+
updated_at:
|
15
|
+
bender:
|
16
|
+
first_name: Bender
|
17
|
+
last_name: Rodriguez
|
18
|
+
occupation: Bending Unit
|
19
|
+
company_id: 1
|
20
|
+
created_at: <%= 1.day.ago.to_s(:db) %>
|
21
|
+
updated_at:
|
22
|
+
walt:
|
23
|
+
first_name: Walt
|
24
|
+
last_name: Unknown
|
25
|
+
occupation: Stooge
|
26
|
+
company_id: 2
|
27
|
+
created_at: <%= 1.day.ago.to_s(:db) %>
|
28
|
+
updated_at:
|
@@ -0,0 +1,18 @@
|
|
1
|
+
ActiveRecord::Schema.define do
|
2
|
+
|
3
|
+
create_table "employees", :force => true do |t|
|
4
|
+
t.column "first_name", :string
|
5
|
+
t.column "last_name", :string
|
6
|
+
t.column "occupation", :string
|
7
|
+
t.column "company_id", :integer
|
8
|
+
t.column "created_at", :datetime
|
9
|
+
t.column "updated_at", :datetime
|
10
|
+
end
|
11
|
+
|
12
|
+
create_table "companies", :force => true do |t|
|
13
|
+
t.column "name", :string
|
14
|
+
t.column "abbrev", :string
|
15
|
+
t.column "descriptors", :text
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'rubygems'
|
3
|
+
|
4
|
+
# gem install redgreen for colored test output
|
5
|
+
begin require 'redgreen'; rescue LoadError; end
|
6
|
+
|
7
|
+
require 'boot' unless defined?(ActiveRecord)
|
8
|
+
|
9
|
+
require 'active_record'
|
10
|
+
|
11
|
+
require "../lib/searchable_by"
|
12
|
+
ActiveRecord::Base.send(:include, Offtheline::SearchableBy)
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'lib/activerecord_test_connector'
|
2
|
+
|
3
|
+
class ActiveRecordTestCase < Test::Unit::TestCase
|
4
|
+
if defined?(ActiveSupport::Testing::SetupAndTeardown)
|
5
|
+
include ActiveSupport::Testing::SetupAndTeardown
|
6
|
+
end
|
7
|
+
|
8
|
+
if defined?(ActiveRecord::TestFixtures)
|
9
|
+
include ActiveRecord::TestFixtures
|
10
|
+
end
|
11
|
+
# Set our fixture path
|
12
|
+
if ActiveRecordTestConnector.able_to_connect
|
13
|
+
self.fixture_path = File.join(File.dirname(__FILE__), '..', 'fixtures')
|
14
|
+
self.use_transactional_fixtures = true
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.fixtures(*args)
|
18
|
+
super if ActiveRecordTestConnector.connected
|
19
|
+
end
|
20
|
+
|
21
|
+
def run(*args)
|
22
|
+
super if ActiveRecordTestConnector.connected
|
23
|
+
end
|
24
|
+
|
25
|
+
# Default so Test::Unit::TestCase doesn't complain
|
26
|
+
def test_truth
|
27
|
+
end
|
28
|
+
|
29
|
+
protected
|
30
|
+
|
31
|
+
def assert_queries(num = 1)
|
32
|
+
$query_count = 0
|
33
|
+
yield
|
34
|
+
ensure
|
35
|
+
assert_equal num, $query_count, "#{$query_count} instead of #{num} queries were executed."
|
36
|
+
end
|
37
|
+
|
38
|
+
def assert_no_queries(&block)
|
39
|
+
assert_queries(0, &block)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
ActiveRecordTestConnector.setup
|