ransack_abbreviator 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,47 @@
1
+ require 'machinist/active_record'
2
+ require 'sham'
3
+ require 'faker'
4
+ require 'ransack'
5
+ require 'ransack_abbreviator'
6
+ require 'pry'
7
+
8
+ Dir[File.expand_path('../{helpers,support,blueprints}/*.rb', __FILE__)].each do |f|
9
+ require f
10
+ end
11
+
12
+ Sham.define do
13
+ name { Faker::Name.name }
14
+ middle_name { Faker::Name.name }
15
+ title { Faker::Lorem.sentence }
16
+ body { Faker::Lorem.paragraph }
17
+ salary {|index| 30000 + (index * 1000)}
18
+ tag_name { Faker::Lorem.words(3).join(' ') }
19
+ note { Faker::Lorem.words(7).join(' ') }
20
+ end
21
+
22
+ RSpec.configure do |config|
23
+ config.include RansackAbbreviator::ViewHelpers
24
+
25
+ config.before(:suite) do
26
+ puts '=' * 80
27
+ puts "Running specs against ActiveRecord #{ActiveRecord::VERSION::STRING} and ARel #{Arel::VERSION}..."
28
+ puts '=' * 80
29
+ Schema.create
30
+ end
31
+
32
+ config.before(:all) { Sham.reset(:before_all) }
33
+ config.before(:each) { Sham.reset(:before_each) }
34
+ end
35
+
36
+ RSpec::Matchers.define :be_like do |expected|
37
+ match do |actual|
38
+ actual.gsub(/^\s+|\s+$/, '').gsub(/\s+/, ' ').strip ==
39
+ expected.gsub(/^\s+|\s+$/, '').gsub(/\s+/, ' ').strip
40
+ end
41
+ end
42
+
43
+ RSpec::Matchers.define :have_attribute_method do |expected|
44
+ match do |actual|
45
+ actual.attribute_method?(expected)
46
+ end
47
+ end
@@ -0,0 +1,105 @@
1
+ require 'active_record'
2
+
3
+ ActiveRecord::Base.establish_connection(
4
+ :adapter => 'sqlite3',
5
+ :database => ':memory:'
6
+ )
7
+
8
+ class Person < ActiveRecord::Base
9
+ belongs_to :parent, :class_name => 'Person', :foreign_key => :parent_id
10
+ has_many :children, :class_name => 'Person', :foreign_key => :parent_id
11
+ has_many :articles
12
+ has_many :comments
13
+ has_many :authored_article_comments, :through => :articles,
14
+ :source => :comments, :foreign_key => :person_id
15
+ has_many :notes, :as => :notable
16
+ end
17
+
18
+ class Article < ActiveRecord::Base
19
+ belongs_to :person
20
+ has_many :comments
21
+ has_and_belongs_to_many :tags
22
+ has_many :notes, :as => :notable
23
+ end
24
+
25
+ class Comment < ActiveRecord::Base
26
+ belongs_to :article
27
+ belongs_to :person
28
+ end
29
+
30
+ class Tag < ActiveRecord::Base
31
+ has_and_belongs_to_many :articles
32
+ end
33
+
34
+ class Note < ActiveRecord::Base
35
+ belongs_to :notable, :polymorphic => true
36
+ end
37
+
38
+ module Schema
39
+ def self.create
40
+ ActiveRecord::Base.silence do
41
+ ActiveRecord::Migration.verbose = false
42
+
43
+ ActiveRecord::Schema.define do
44
+ create_table :people, :force => true do |t|
45
+ t.integer :parent_id
46
+ t.string :name
47
+ t.string :middle_name
48
+ t.integer :salary
49
+ t.boolean :awesome, :default => false
50
+ t.timestamps
51
+ end
52
+
53
+ create_table :articles, :force => true do |t|
54
+ t.integer :person_id
55
+ t.string :title
56
+ t.text :body
57
+ end
58
+
59
+ create_table :comments, :force => true do |t|
60
+ t.integer :article_id
61
+ t.integer :person_id
62
+ t.text :body
63
+ t.integer :vote_count
64
+ end
65
+
66
+ create_table :tags, :force => true do |t|
67
+ t.string :name
68
+ end
69
+
70
+ create_table :articles_tags, :force => true, :id => false do |t|
71
+ t.integer :article_id
72
+ t.integer :tag_id
73
+ end
74
+
75
+ create_table :notes, :force => true do |t|
76
+ t.integer :notable_id
77
+ t.string :notable_type
78
+ t.string :note
79
+ end
80
+
81
+ end
82
+ end
83
+
84
+ 10.times do
85
+ person = Person.make
86
+ Note.make(:notable => person)
87
+ 3.times do
88
+ article = Article.make(:person => person)
89
+ 3.times do
90
+ article.tags = [Tag.make, Tag.make, Tag.make]
91
+ end
92
+ Note.make(:notable => article)
93
+ 10.times do
94
+ Comment.make(:article => article)
95
+ end
96
+ end
97
+ 2.times do
98
+ Comment.make(:person => person)
99
+ end
100
+ end
101
+
102
+ Comment.make(:body => 'First post!', :article => Article.make(:title => 'Hello, world!'))
103
+
104
+ end
105
+ end
metadata ADDED
@@ -0,0 +1,160 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ransack_abbreviator
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.1
6
+ platform: ruby
7
+ authors:
8
+ - Jamie Davidson
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2013-02-03 00:00:00 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: ransack
17
+ prerelease: false
18
+ requirement: &id001 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ~>
22
+ - !ruby/object:Gem::Version
23
+ version: "0.7"
24
+ type: :runtime
25
+ version_requirements: *id001
26
+ - !ruby/object:Gem::Dependency
27
+ name: pry
28
+ prerelease: false
29
+ requirement: &id002 !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: "0"
35
+ type: :development
36
+ version_requirements: *id002
37
+ - !ruby/object:Gem::Dependency
38
+ name: rspec
39
+ prerelease: false
40
+ requirement: &id003 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 2.8.0
46
+ type: :development
47
+ version_requirements: *id003
48
+ - !ruby/object:Gem::Dependency
49
+ name: machinist
50
+ prerelease: false
51
+ requirement: &id004 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ~>
55
+ - !ruby/object:Gem::Version
56
+ version: 1.0.6
57
+ type: :development
58
+ version_requirements: *id004
59
+ - !ruby/object:Gem::Dependency
60
+ name: faker
61
+ prerelease: false
62
+ requirement: &id005 !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ~>
66
+ - !ruby/object:Gem::Version
67
+ version: 0.9.5
68
+ type: :development
69
+ version_requirements: *id005
70
+ - !ruby/object:Gem::Dependency
71
+ name: sqlite3
72
+ prerelease: false
73
+ requirement: &id006 !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ~>
77
+ - !ruby/object:Gem::Version
78
+ version: 1.3.3
79
+ type: :development
80
+ version_requirements: *id006
81
+ description: Avoid POSTs. Abbreviate those Ransack queries.
82
+ email:
83
+ - jhdavids8@gmail.com
84
+ executables: []
85
+
86
+ extensions: []
87
+
88
+ extra_rdoc_files: []
89
+
90
+ files:
91
+ - .gitignore
92
+ - CHANGELOG.md
93
+ - Gemfile
94
+ - LICENSE
95
+ - README.md
96
+ - Rakefile
97
+ - lib/ransack_abbreviator.rb
98
+ - lib/ransack_abbreviator/abbreviators/decoder.rb
99
+ - lib/ransack_abbreviator/abbreviators/encoder.rb
100
+ - lib/ransack_abbreviator/adapters/active_record.rb
101
+ - lib/ransack_abbreviator/adapters/active_record/base.rb
102
+ - lib/ransack_abbreviator/configuration.rb
103
+ - lib/ransack_abbreviator/constants.rb
104
+ - lib/ransack_abbreviator/ransack_extensions/context.rb
105
+ - lib/ransack_abbreviator/ransack_extensions/nodes/condition.rb
106
+ - lib/ransack_abbreviator/ransack_extensions/nodes/grouping.rb
107
+ - lib/ransack_abbreviator/ransack_extensions/search.rb
108
+ - lib/ransack_abbreviator/version.rb
109
+ - lib/ransack_abbreviator/view_helpers.rb
110
+ - ransack_abbreviator.gemspec
111
+ - spec/blueprints/articles.rb
112
+ - spec/blueprints/comments.rb
113
+ - spec/blueprints/notes.rb
114
+ - spec/blueprints/people.rb
115
+ - spec/blueprints/tags.rb
116
+ - spec/ransack_abbreviator/adapters/active_record/base_spec.rb
117
+ - spec/ransack_abbreviator/configuration_spec.rb
118
+ - spec/ransack_abbreviator/helper_spec.rb
119
+ - spec/ransack_abbreviator/search_spec.rb
120
+ - spec/spec_helper.rb
121
+ - spec/support/schema.rb
122
+ homepage: https://github.com/jhdavids8/ransack-abbreviator
123
+ licenses: []
124
+
125
+ post_install_message:
126
+ rdoc_options: []
127
+
128
+ require_paths:
129
+ - lib
130
+ required_ruby_version: !ruby/object:Gem::Requirement
131
+ none: false
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: "0"
136
+ required_rubygems_version: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ">="
140
+ - !ruby/object:Gem::Version
141
+ version: "0"
142
+ requirements: []
143
+
144
+ rubyforge_project: ransack_abbreviator
145
+ rubygems_version: 1.8.24
146
+ signing_key:
147
+ specification_version: 3
148
+ summary: Avoid POSTs. Abbreviate those Ransack queries.
149
+ test_files:
150
+ - spec/blueprints/articles.rb
151
+ - spec/blueprints/comments.rb
152
+ - spec/blueprints/notes.rb
153
+ - spec/blueprints/people.rb
154
+ - spec/blueprints/tags.rb
155
+ - spec/ransack_abbreviator/adapters/active_record/base_spec.rb
156
+ - spec/ransack_abbreviator/configuration_spec.rb
157
+ - spec/ransack_abbreviator/helper_spec.rb
158
+ - spec/ransack_abbreviator/search_spec.rb
159
+ - spec/spec_helper.rb
160
+ - spec/support/schema.rb