searcher_generator 1.0.2 → 1.0.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2d60852f3230df8c8bd13332b71c4517dbb8d200
4
- data.tar.gz: 23ab4f9d6ee7da99b9640343b8b265af3ba86062
3
+ metadata.gz: 26dbab64e0c77beef8c9e101d4b140d6998aa833
4
+ data.tar.gz: c5c8ed1c09dcd1a464c8d595f0393b6f9f97ee2d
5
5
  SHA512:
6
- metadata.gz: 57a0c212e4c7c3dbdbe6672980ce3d40841f9ab9bd32205e24aa2f987d1c92c92647e513efbc01180635084283b29b587c7cc20ceb4041b50938f332ee2f16de
7
- data.tar.gz: 8b7fda75c41003c04c7a20b2ba8aab93b680af40bc85f7f9a1b260c673bdb2fd373bf68981e6f819af6fe28d8d70352fdf594b7723b5a0e42cd508ecd3757ac2
6
+ metadata.gz: 97fac6636da7c85304133bb9c51022e86c068ee59966f9c1462c3e1cdc738f86f576d83fe043f2d6aa7c2e6853d2e7a9bfae547c29f439c2a9124d0455bed596
7
+ data.tar.gz: b46a462f5005546eb146615fb0de50594f1daecdd43e0cbd5f828ef2cd274fbc83448644755880904e492f891e503333db602d5914ae5657860b907e6ad5209d
@@ -17,6 +17,7 @@ Example:
17
17
  (iii) e$ - it will create enum type attribute
18
18
  (iv) approval_status@ - it will create approval_status attribute
19
19
  (v) page@ - it will create page attribute
20
+ (vi) yes$ - it will create yes no input type
20
21
 
21
22
  Things to do after running this command
22
23
  1- changes in routes file
@@ -17,6 +17,10 @@ class SearchGenerator < Rails::Generators::Base
17
17
  template 'en.yml', "config/locales/models/#{model_name.underscore}/en.yml"
18
18
  end
19
19
 
20
+ def generate_spec_file
21
+ template 'searcher_spec.rb', "spec/searchers/#{model_name.underscore}_searcher_spec.rb"
22
+ end
23
+
20
24
  def inject_searcher_params
21
25
  inject_into_file("app/controllers/#{model_name.pluralize.underscore}_controller.rb", :after => 'private') do
22
26
  searcher_params_content
@@ -63,6 +67,9 @@ class SearchGenerator < Rails::Generators::Base
63
67
  elsif k.include?("approval_status@")
64
68
  k = k.chomp("@")
65
69
  f = f+":#{k}, "
70
+ elsif k.include?("yes$")
71
+ k = k.chomp("yes$")
72
+ f = f+":#{k}, "
66
73
  else
67
74
  f = f+":#{k}, "
68
75
  end
@@ -1,4 +1,4 @@
1
- = search_form_for @searcher do |f|
1
+ = search_form_for @searcher, {defaults: local_assigns[:defaults]} do |f|
2
2
  = f.standard_fields
3
3
  <% attributes.each do |attr|-%>
4
4
  <% if attr[0].include?("approval_status@") or attr[0].include?("page@") or attr[0].include?("humanize_model@")-%>
@@ -8,6 +8,8 @@
8
8
  = f.input :<%=attr[0].chomp('bet1')%>, as: :between
9
9
  <% elsif attr[0].include?("bet$") -%>
10
10
  = f.input :<%=attr[0].chomp('bet$')%>, as: :between
11
+ <% elsif attr[0].include?("yes$") -%>
12
+ = f.input :<%=attr[0].chomp('yes$')%>, as: :yesno
11
13
  <% else -%>
12
14
  = f.input :<%=attr[0]%>
13
15
  <% end -%>
@@ -12,6 +12,8 @@ en:
12
12
  <%=attr[0].chomp('bet$')%>: "<%= attr[1]%>"
13
13
  <% elsif attr[0].include?("bet1") -%>
14
14
  <%=attr[0].chomp('bet1')%>: "<%= attr[1]%>"
15
+ <% elsif attr[0].include?("yes$") -%>
16
+ <%=attr[0].chomp('yes$')%>: "<%= attr[1]%>"
15
17
  <% else -%>
16
18
  <%=attr[0]%>: "<%= attr[1]%>"
17
19
  <% end -%>
@@ -0,0 +1,49 @@
1
+ require 'spec_helper'
2
+ <% small_model_name = model_name.underscore%>
3
+ describe <%=model_name%>Searcher do
4
+ context 'searcher' do
5
+ it 'should return <%=small_model_name%>' do
6
+ <% get_attributes.each do |attr| -%>
7
+ <% if attr[0].include?('bet$')-%>
8
+ <% attr[0] = attr[0].chomp('bet$')-%>
9
+ <%=small_model_name%>s = [Factory(:<%=small_model_name%>, :<%=attr[0]%> => "<%=1.year.ago.to_s%>")]
10
+ <%=small_model_name%>s << Factory(:<%=small_model_name%>, :<%=attr[0]%> => "<%=6.months.ago.to_s%>")
11
+ <%=model_name%>Searcher.new({from_<%=attr[0]%>: "<%=13.months.ago.to_s%>", to_<%=attr[0]%>: "<%=7.months.ago.to_s%>" }).paginate.should == [<%=small_model_name%>s[0]]
12
+ <%=model_name%>Searcher.new({from_<%=attr[0]%>: "<%=13.months.ago.to_s%>", to_<%=attr[0]%>: "<%=2.months.from_now.to_s%>" }).paginate.should == <%=small_model_name%>s.reverse
13
+
14
+ <% elsif attr[0].include?('bet1')-%>
15
+ <% attr[0] = attr[0].chomp('bet1')-%>
16
+ <%=small_model_name%>s = [Factory(:<%=small_model_name%>, :<%=attr[0]%> => <%= 100%>)]
17
+ <%=small_model_name%>s << Factory(:<%=small_model_name%>, :<%=attr[0]%> => <%= 200%>)
18
+ <%=model_name%>Searcher.new({from_<%=attr[0]%>: <%= 50 %>, to_<%=attr[0]%>: <%= 150 %> }).paginate.should == [<%=small_model_name%>s[0]]
19
+ <%=model_name%>Searcher.new({from_<%=attr[0]%>: <%= 50 %>, to_<%=attr[0]%>: <%= 200 %> }).paginate.should == <%=small_model_name%>s.reverse
20
+
21
+ <% elsif attr[0].include?('e$')-%>
22
+ <% attr[0] = attr[0].chomp('e$')-%>
23
+ <%=small_model_name%> = Factory(:<%=small_model_name%>, :<%=attr[0]%> => 'STRING1')
24
+ <%=model_name%>Searcher.new({<%= attr[0]%>: 'STRING1'}).paginate.should == [<%=small_model_name%>]
25
+ <%=model_name%>Searcher.new({<%= attr[0]%>: 'STRING2'}).paginate.should == []
26
+
27
+ <% elsif attr[0].include?('yes$')-%>
28
+ <% attr[0] = attr[0].chomp('yes$')-%>
29
+ <%=small_model_name%> = Factory(:<%=small_model_name%>, :<%=attr[0]%> => 'Y')
30
+ <%=model_name%>Searcher.new({<%= attr[0]%>: 'Y'}).paginate.should == [<%=small_model_name%>]
31
+ <%=model_name%>Searcher.new({<%= attr[0]%>: 'N'}).paginate.should == []
32
+
33
+ <% elsif attr[0].include?('page@') or attr[0].include?('humanize_model@')-%>
34
+ <% elsif attr[0].include?('approval_status@')-%>
35
+ <% attr[0] = attr[0].chomp('@')-%>
36
+ <%=small_model_name%> = Factory(:<%=small_model_name%>, :<%=attr[0]%> => 'U')
37
+ <%=model_name%>Searcher.new({<%= attr[0]%>: 'U'}).paginate.should == [<%=small_model_name%>]
38
+ <%=model_name%>Searcher.new({<%= attr[0]%>: 'A'}).paginate.should == []
39
+
40
+ <% else -%>
41
+ <%=small_model_name%> = Factory(:<%=small_model_name%>, :<%=attr[0]%> => 'STRING1')
42
+ <%=model_name%>Searcher.new({<%= attr[0]%>: 'STRING1'}).paginate.should == [<%=small_model_name%>]
43
+ <%=model_name%>Searcher.new({<%= attr[0]%>: 'STRING2'}).paginate.should == []
44
+
45
+ <% end -%>
46
+ <% end -%>
47
+ end
48
+ end
49
+ end
@@ -1,3 +1,3 @@
1
1
  module SearcherGenerator
2
- VERSION = "1.0.2"
2
+ VERSION = "1.0.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: searcher_generator
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - pawan bora
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-10-13 00:00:00.000000000 Z
11
+ date: 2017-10-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -74,6 +74,7 @@ files:
74
74
  - lib/generators/search/templates/advanced_search.html.haml
75
75
  - lib/generators/search/templates/en.yml
76
76
  - lib/generators/search/templates/searcher.rb
77
+ - lib/generators/search/templates/searcher_spec.rb
77
78
  - lib/searcher_generator.rb
78
79
  - lib/searcher_generator/version.rb
79
80
  - searcher_generator.gemspec