sql_search_n_sort 2.1.1 → 2.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/lib/generators/sql_search_n_sort/config/initializers/sql_search_n_sort.rb +7 -0
  3. data/lib/generators/sql_search_n_sort/install_generator.rb +9 -2
  4. data/lib/generators/sql_search_n_sort/views/application/_search_form.html.haml +1 -0
  5. data/lib/generators/sql_search_n_sort/views/application/_sort_form.html.haml +1 -0
  6. data/lib/sql_search_n_sort/app/helpers/sql_search_n_sort_helper.rb +2 -1
  7. data/lib/sql_search_n_sort/version.rb +1 -1
  8. data/lib/sql_search_n_sort.rb +8 -0
  9. data/test/dummy/app/controllers/items_controller.rb +5 -0
  10. data/test/dummy/app/models/item.rb +5 -0
  11. data/test/dummy/app/views/items/index.html.haml +2 -0
  12. data/test/dummy/config/database.yml +45 -20
  13. data/test/dummy/config/routes.rb +1 -0
  14. data/test/dummy/db/development.sqlite3 +0 -0
  15. data/test/dummy/db/migrate/20160128023040_create_items.rb +8 -0
  16. data/test/dummy/db/schema.rb +16 -3
  17. data/test/dummy/db/test.sqlite3 +0 -0
  18. data/test/dummy/log/development.log +79 -0
  19. data/test/dummy/log/test.log +108025 -0
  20. data/test/dummy/spec/helpers/sql_search_n_sort_helper_spec.rb +35 -0
  21. data/test/dummy/spec/requests/items_spec.rb +52 -0
  22. data/test/dummy/spec/requests/people_spec.rb +1 -4
  23. data/test/dummy/spec/spec_helper.rb +2 -0
  24. data/test/dummy/tmp/cache/assets/test/sprockets/13fe41fee1fe35b49d145bcc06610705 +0 -0
  25. data/test/dummy/tmp/cache/assets/test/sprockets/1dc2824e4f69b5f787cc0b33a280e1f7 +0 -0
  26. data/test/dummy/tmp/cache/assets/test/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
  27. data/test/dummy/tmp/cache/assets/test/sprockets/357970feca3ac29060c1e3861e2c0953 +0 -0
  28. data/test/dummy/tmp/cache/assets/test/sprockets/629a9a26184f65bc7adea5578662128f +0 -0
  29. data/test/dummy/tmp/cache/assets/test/sprockets/65c86772572f7601d47c9089124fe58e +0 -0
  30. data/test/dummy/tmp/cache/assets/test/sprockets/991d9baf4c0665d4114d00882965f72c +0 -0
  31. data/test/dummy/tmp/cache/assets/test/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
  32. data/test/dummy/tmp/cache/assets/test/sprockets/d771ace226fc8215a3572e0aa35bb0d6 +0 -0
  33. data/test/dummy/tmp/cache/assets/test/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
  34. data/test/generators/sql_search_n_sort/install_test.rb +3 -3
  35. metadata +31 -16
  36. data/test/dummy/tmp/pids/server.pid +0 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7ac91912096e4c2f8adf0cd43a32bef0cc2552e0
4
- data.tar.gz: dd21e920b303b9a5ace1135f158e908d4f537931
3
+ metadata.gz: c9b55c9a2d00587e07696f93ff19868e14d6a6c9
4
+ data.tar.gz: e5c0d59ba01b3545fc8a35d0bdce2a06fe262f0e
5
5
  SHA512:
6
- metadata.gz: c37f5a314fb9fb7bbbcdc8998650698727f6aafe6c56d686c4070f65b2c61c1fe8898121e5e320c6a6b7c24a984e65c80c0ae09542059a49e2c831bcf486fdf4
7
- data.tar.gz: ca4c580cb2364f07d57a3158d316fd8cad3d61bd7689d5694e84f62080e1939302a47d215c7c3eb230bab1c152c32345599f6ca3d2d8aac0c9f735f0a34c8763
6
+ metadata.gz: 9bf247d3abf1332d504d9c13894de7af486a060339ea91fa008aac62007f2845f917a669ff2b4c8a4295c86991d3232de7c42b1df1b7b81925d4b2cba90f080c
7
+ data.tar.gz: baa89ed908b98744a5ee90fae20d5fa36287bc99c875bdfd1a47520f0a4f6c63aa21956412352703f300e3a6b5fa6576ce9757627508a9c28cb0c7b868996003
@@ -0,0 +1,7 @@
1
+ SqlSearchNSort.config do |config|
2
+ #Add to this array any parameters you don't want the search/sort forms to pass along . (like "page" in Kaminari)
3
+ config.suppress_params = {
4
+ search: [],
5
+ sort: []
6
+ }
7
+ end
@@ -1,10 +1,12 @@
1
1
  require 'rails/generators'
2
+
2
3
  module SqlSearchNSort
3
4
  class InstallGenerator < Rails::Generators::Base
4
5
 
5
6
  source_paths << File.expand_path('../views/application', __FILE__)
6
7
  source_paths << File.expand_path('../assets/javascripts', __FILE__)
7
8
  source_paths << File.expand_path('../helpers', __FILE__)
9
+ source_paths << File.expand_path('../config/initializers', __FILE__)
8
10
 
9
11
  def copy_files
10
12
  base_path = "app/views/application"
@@ -13,14 +15,19 @@ module SqlSearchNSort
13
15
 
14
16
  base_path = "app/assets/javascripts"
15
17
  copy_file('sql_search_n_sort.js', File.join(base_path, 'sql_search_n_sort.js'))
16
-
18
+
19
+ base_path = "config/initializers"
20
+ copy_file('sql_search_n_sort.rb', File.join(base_path, 'sql_search_n_sort.rb'))
17
21
  end
18
22
 
19
23
  def require_jquery
20
- inject_into_file "app/assets/javascripts/application.js",
24
+ #could be either application.js or application.js.coffee or maybe something else in the future
25
+ if app_js_fl = Dir["#{destination_root}/app/assets/javascripts/*"].select{|f| f =~ /application\.js/}.first
26
+ inject_into_file app_js_fl,
21
27
  before: "\n//= require_tree ." do
22
28
  "\n//= require jquery"
23
29
  end
30
+ end
24
31
  end
25
32
 
26
33
  def insert_into_app_controller
@@ -1,3 +1,4 @@
1
+ - @mode = :search
1
2
  %form{id: "search-form"}
2
3
  = hide_current_params("search_for").html_safe
3
4
  =text_field_tag :search_for, params[:search_for], :placeholder => "Search"
@@ -1,3 +1,4 @@
1
+ - @mode = :sort
1
2
  %form
2
3
  = hide_current_params("sort_by").html_safe
3
4
  = label_tag :sort_by
@@ -1,8 +1,9 @@
1
1
  module SqlSearchNSortHelper
2
2
 
3
- #Should only be used for forms performing a GET
3
+ #Should only be used for forms performing a GET (which they all should be)
4
4
  def hide_current_params(*suppress)
5
5
  return "" if request.query_parameters.empty?
6
+ suppress.concat(SqlSearchNSort.config.suppress_params[@mode] || [])
6
7
  request.query_parameters.reject { |k, v| suppress.include?(k) }.map do |k, v|
7
8
  hidden_field_tag(k, v)
8
9
  end.join("\n")
@@ -1,3 +1,3 @@
1
1
  module SqlSearchNSort
2
- VERSION = "2.1.1"
2
+ VERSION = "2.1.2"
3
3
  end
@@ -6,4 +6,12 @@ module SqlSearchNSort
6
6
  require "factory_girl_rails" if Rails.env == 'test'
7
7
  require "haml-rails"
8
8
  require "jquery-rails"
9
+
10
+ class Engine < Rails::Engine
11
+ end
12
+
13
+ def self.config(&block)
14
+ yield Engine.config if block
15
+ Engine.config
16
+ end
9
17
  end
@@ -0,0 +1,5 @@
1
+ class ItemsController < ApplicationController
2
+ def index
3
+
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ class Item < ActiveRecord::Base
2
+ extend SqlSearchableSortable
3
+ sql_searchable :name, :descr
4
+ sql_sortable :name, :descr
5
+ end
@@ -0,0 +1,2 @@
1
+ = render 'search_form'
2
+ = render 'sort_form'
@@ -1,25 +1,50 @@
1
- # SQLite version 3.x
2
- # gem install sqlite3
3
- #
4
- # Ensure the SQLite 3 gem is defined in your Gemfile
5
- # gem 'sqlite3'
6
- #
7
- default: &default
8
- adapter: sqlite3
9
- pool: 5
10
- timeout: 5000
1
+ # default: &default
2
+ # adapter: sqlite3
3
+ # pool: 5
4
+ # timeout: 5000
5
+
6
+ # development:
7
+ # <<: *default
8
+ # database: db/development.sqlite3
9
+
10
+ # test:
11
+ # <<: *default
12
+ # database: db/test.sqlite3
13
+
14
+ # production:
15
+ # <<: *default
16
+ # database: db/production.sqlite3
11
17
 
12
18
  development:
13
- <<: *default
14
- database: db/development.sqlite3
19
+ adapter: mysql2
20
+ encoding: utf8
21
+ reconnect: false
22
+ database: ssns_development
23
+ pool: 5
24
+ username: ssns
25
+ password: toolman1
26
+ socket: /tmp/mysql.sock
27
+ timeout: 5000
15
28
 
16
- # Warning: The database defined as "test" will be erased and
17
- # re-generated from your development database when you run "rake".
18
- # Do not set this db to the same as development or production.
19
29
  test:
20
- <<: *default
21
- database: db/test.sqlite3
30
+ adapter: mysql2
31
+ encoding: utf8
32
+ reconnect: false
33
+ database: ssns_test
34
+ pool: 5
35
+ username: ssns
36
+ password: toolman1
37
+ socket: /tmp/mysql.sock
38
+ timeout: 5000
39
+
40
+ # production:
41
+ # adapter: mysql2
42
+ # encoding: utf8
43
+ # reconnect: false
44
+ # database: sql-search-n-sort_production
45
+ # pool: 5
46
+ # username: ssns
47
+ # password: toolman1
48
+ # socket: /tmp/mysql.sock
49
+ # timeout: 5000
22
50
 
23
- production:
24
- <<: *default
25
- database: db/production.sqlite3
@@ -15,6 +15,7 @@ Rails.application.routes.draw do
15
15
  get "/search_vehicles" => 'vehicles#search_only_index'
16
16
  get "/sort_vehicles" => 'vehicles#sort_only_index'
17
17
  get "/unsearchables" => 'unsearchables#index'
18
+ get "/items" => "items#index"
18
19
 
19
20
  scope module: "admin" do
20
21
  get "members" => 'members#index_explicit_setup', as: 'admin_members'
Binary file
@@ -0,0 +1,8 @@
1
+ class CreateItems < ActiveRecord::Migration
2
+ def change
3
+ create_table :items do |t|
4
+ t.string :name
5
+ t.text :descr
6
+ end
7
+ end
8
+ end
@@ -11,7 +11,7 @@
11
11
  #
12
12
  # It's strongly recommended that you check this file into your version control system.
13
13
 
14
- ActiveRecord::Schema.define(version: 20150306040113) do
14
+ ActiveRecord::Schema.define(version: 20160128023040) do
15
15
 
16
16
  create_table "articles", force: true do |t|
17
17
  t.string "headline"
@@ -22,6 +22,19 @@ ActiveRecord::Schema.define(version: 20150306040113) do
22
22
  t.datetime "updated_at"
23
23
  end
24
24
 
25
+ create_table "comments", force: true do |t|
26
+ t.text "ctext"
27
+ t.string "commentator"
28
+ t.datetime "created_at"
29
+ t.datetime "updated_at"
30
+ t.integer "article_id"
31
+ end
32
+
33
+ create_table "items", force: true do |t|
34
+ t.string "name"
35
+ t.text "descr"
36
+ end
37
+
25
38
  create_table "members", force: true do |t|
26
39
  t.string "first_name"
27
40
  t.string "last_name"
@@ -59,8 +72,8 @@ ActiveRecord::Schema.define(version: 20150306040113) do
59
72
  t.time "tm"
60
73
  t.datetime "dtm"
61
74
  t.boolean "bool"
62
- t.float "flt"
63
- t.decimal "dec"
75
+ t.float "flt", limit: 24
76
+ t.decimal "dec", precision: 10, scale: 0
64
77
  t.binary "bn"
65
78
  t.datetime "ts"
66
79
  t.datetime "created_at"
Binary file
@@ -10480,3 +10480,82 @@ Started GET "/assets/sql_search_n_sort.js?body=1" for 127.0.0.1 at 2015-03-11 19
10480
10480
 
10481
10481
 
10482
10482
  Started GET "/assets/jquery.js?body=1" for 127.0.0.1 at 2015-03-11 19:47:32 -0400
10483
+ ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
10484
+ Migrating to CreateComments (20160121020023)
10485
+  (0.1ms) begin transaction
10486
+  (0.6ms) CREATE TABLE "comments" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "ctext" text, "commentator" varchar(255)) 
10487
+ SQL (0.2ms) INSERT INTO "schema_migrations" ("version") VALUES (?) [["version", "20160121020023"]]
10488
+  (1.2ms) commit transaction
10489
+ ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
10490
+ ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
10491
+ Migrating to AddTimestampsToComments (20160121020232)
10492
+  (0.1ms) begin transaction
10493
+  (1.0ms) ALTER TABLE "comments" ADD "created_at" datetime
10494
+  (0.1ms) ALTER TABLE "comments" ADD "updated_at" datetime
10495
+ SQL (0.2ms) INSERT INTO "schema_migrations" ("version") VALUES (?) [["version", "20160121020232"]]
10496
+  (5.5ms) commit transaction
10497
+ ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
10498
+ ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
10499
+ Migrating to AddArticleIdToComments (20160121020730)
10500
+  (0.1ms) begin transaction
10501
+  (0.5ms) ALTER TABLE "comments" ADD "article_id" integer
10502
+ SQL (0.2ms) INSERT INTO "schema_migrations" ("version") VALUES (?) [["version", "20160121020730"]]
10503
+  (5.5ms) commit transaction
10504
+ ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
10505
+ ActiveRecord::SchemaMigration Load (0.2ms) SELECT "schema_migrations".* FROM "schema_migrations"
10506
+ Migrating to CreateItems (20160128023040)
10507
+  (0.1ms) begin transaction
10508
+  (0.5ms) CREATE TABLE "items" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255), "descr" text) 
10509
+ SQL (0.3ms) INSERT INTO "schema_migrations" ("version") VALUES (?) [["version", "20160128023040"]]
10510
+  (1.3ms) commit transaction
10511
+ ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
10512
+ Mysql2::Error: Table 'sql-search-n-sort_development.members' doesn't exist: SHOW FULL FIELDS FROM `members`
10513
+ Mysql2::Error: Table 'ssns_development.members' doesn't exist: SHOW FULL FIELDS FROM `members`
10514
+ Mysql2::Error: Table 'ssns_development.members' doesn't exist: SHOW FULL FIELDS FROM `members`
10515
+ Mysql2::Error: Table 'ssns_development.members' doesn't exist: SHOW FULL FIELDS FROM `members`
10516
+ Mysql2::Error: Table 'ssns_development.members' doesn't exist: SHOW FULL FIELDS FROM `members`
10517
+  (119.9ms) CREATE TABLE `articles` (`id` int(11) auto_increment PRIMARY KEY, `headline` varchar(255), `by_line` varchar(255), `date_pub` datetime, `body` text, `created_at` datetime, `updated_at` datetime) ENGINE=InnoDB
10518
+  (180.4ms) CREATE TABLE `comments` (`id` int(11) auto_increment PRIMARY KEY, `ctext` text, `commentator` varchar(255), `created_at` datetime, `updated_at` datetime, `article_id` int(11)) ENGINE=InnoDB
10519
+  (215.1ms) CREATE TABLE `items` (`id` int(11) auto_increment PRIMARY KEY, `name` varchar(255), `descr` text) ENGINE=InnoDB
10520
+  (174.9ms) CREATE TABLE `people` (`id` int(11) auto_increment PRIMARY KEY, `first_name` varchar(255), `last_name` varchar(255), `age` int(11), `email` varchar(255), `bio` text, `nickname` varchar(255), `created_at` datetime, `updated_at` datetime, `dob` datetime, `grade` int(11)) ENGINE=InnoDB
10521
+  (197.9ms) CREATE TABLE `products` (`id` int(11) auto_increment PRIMARY KEY, `name` varchar(255), `descr` text, `price` int(11), `date_produced` datetime, `manufacturer` varchar(255), `created_at` datetime, `updated_at` datetime) ENGINE=InnoDB
10522
+  (188.5ms) CREATE TABLE `unsearchables` (`id` int(11) auto_increment PRIMARY KEY, `int` int(11), `dt` date, `tm` time, `dtm` datetime, `bool` tinyint(1), `flt` float, `dec` decimal, `bn` blob, `ts` datetime, `created_at` datetime, `updated_at` datetime) ENGINE=InnoDB
10523
+  (166.2ms) CREATE TABLE `vehicles` (`id` int(11) auto_increment PRIMARY KEY, `year` int(11), `manufacturer` varchar(255), `model` varchar(255), `color` varchar(255), `engine` varchar(255), `doorrs` int(11), `cylinders` int(11), `created_at` datetime, `updated_at` datetime) ENGINE=InnoDB
10524
+  (158.1ms) CREATE TABLE `schema_migrations` (`version` varchar(255) NOT NULL) ENGINE=InnoDB
10525
+  (201.4ms) CREATE UNIQUE INDEX `unique_schema_migrations` ON `schema_migrations` (`version`) 
10526
+  (0.3ms) SELECT version FROM `schema_migrations`
10527
+  (0.5ms) INSERT INTO `schema_migrations` (version) VALUES ('20160128023040')
10528
+  (0.4ms) INSERT INTO `schema_migrations` (version) VALUES ('20140713221826')
10529
+  (0.4ms) INSERT INTO `schema_migrations` (version) VALUES ('20140715080028')
10530
+  (0.4ms) INSERT INTO `schema_migrations` (version) VALUES ('20140723223003')
10531
+  (0.4ms) INSERT INTO `schema_migrations` (version) VALUES ('20140725015524')
10532
+  (0.4ms) INSERT INTO `schema_migrations` (version) VALUES ('20140725161555')
10533
+  (0.4ms) INSERT INTO `schema_migrations` (version) VALUES ('20141003015903')
10534
+  (0.4ms) INSERT INTO `schema_migrations` (version) VALUES ('20150306040113')
10535
+ Mysql2::Error: Table 'ssns_development.members' doesn't exist: SHOW FULL FIELDS FROM `members`
10536
+  (16.5ms) DROP DATABASE IF EXISTS `ssns_development`
10537
+  (0.5ms) DROP DATABASE IF EXISTS `ssns_test`
10538
+  (0.5ms) CREATE DATABASE `ssns_development` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`
10539
+  (0.5ms) CREATE DATABASE `ssns_test` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`
10540
+  (177.2ms) CREATE TABLE `articles` (`id` int(11) auto_increment PRIMARY KEY, `headline` varchar(255), `by_line` varchar(255), `date_pub` datetime, `body` text, `created_at` datetime, `updated_at` datetime) ENGINE=InnoDB
10541
+  (463.7ms) CREATE TABLE `comments` (`id` int(11) auto_increment PRIMARY KEY, `ctext` text, `commentator` varchar(255), `created_at` datetime, `updated_at` datetime, `article_id` int(11)) ENGINE=InnoDB
10542
+  (144.4ms) CREATE TABLE `items` (`id` int(11) auto_increment PRIMARY KEY, `name` varchar(255), `descr` text) ENGINE=InnoDB
10543
+  (153.6ms) CREATE TABLE `members` (`id` int(11) auto_increment PRIMARY KEY, `first_name` varchar(255), `last_name` varchar(255), `email` varchar(255), `created_at` datetime, `updated_at` datetime) ENGINE=InnoDB
10544
+  (179.2ms) CREATE TABLE `people` (`id` int(11) auto_increment PRIMARY KEY, `first_name` varchar(255), `last_name` varchar(255), `age` int(11), `email` varchar(255), `bio` text, `nickname` varchar(255), `created_at` datetime, `updated_at` datetime, `dob` datetime, `grade` int(11)) ENGINE=InnoDB
10545
+  (156.7ms) CREATE TABLE `products` (`id` int(11) auto_increment PRIMARY KEY, `name` varchar(255), `descr` text, `price` int(11), `date_produced` datetime, `manufacturer` varchar(255), `created_at` datetime, `updated_at` datetime) ENGINE=InnoDB
10546
+  (165.4ms) CREATE TABLE `unsearchables` (`id` int(11) auto_increment PRIMARY KEY, `int` int(11), `dt` date, `tm` time, `dtm` datetime, `bool` tinyint(1), `flt` float, `dec` decimal, `bn` blob, `ts` datetime, `created_at` datetime, `updated_at` datetime) ENGINE=InnoDB
10547
+  (154.3ms) CREATE TABLE `vehicles` (`id` int(11) auto_increment PRIMARY KEY, `year` int(11), `manufacturer` varchar(255), `model` varchar(255), `color` varchar(255), `engine` varchar(255), `doorrs` int(11), `cylinders` int(11), `created_at` datetime, `updated_at` datetime) ENGINE=InnoDB
10548
+  (342.8ms) CREATE TABLE `schema_migrations` (`version` varchar(255) NOT NULL) ENGINE=InnoDB
10549
+  (268.2ms) CREATE UNIQUE INDEX `unique_schema_migrations` ON `schema_migrations` (`version`)
10550
+  (0.3ms) SELECT version FROM `schema_migrations`
10551
+  (0.6ms) INSERT INTO `schema_migrations` (version) VALUES ('20160128023040')
10552
+  (0.5ms) INSERT INTO `schema_migrations` (version) VALUES ('20140713221826')
10553
+  (0.4ms) INSERT INTO `schema_migrations` (version) VALUES ('20140715080028')
10554
+  (0.4ms) INSERT INTO `schema_migrations` (version) VALUES ('20140723223003')
10555
+  (0.4ms) INSERT INTO `schema_migrations` (version) VALUES ('20140725015524')
10556
+  (0.4ms) INSERT INTO `schema_migrations` (version) VALUES ('20140725161555')
10557
+  (0.5ms) INSERT INTO `schema_migrations` (version) VALUES ('20141003015903')
10558
+  (0.3ms) INSERT INTO `schema_migrations` (version) VALUES ('20150306040113')
10559
+ ActiveRecord::SchemaMigration Load (0.2ms) SELECT `schema_migrations`.* FROM `schema_migrations`
10560
+ ActiveRecord::SchemaMigration Load (0.3ms) SELECT `schema_migrations`.* FROM `schema_migrations`
10561
+ ActiveRecord::SchemaMigration Load (0.3ms) SELECT `schema_migrations`.* FROM `schema_migrations`