kashiwamochi 0.4.2 → 0.4.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -8,18 +8,13 @@ module Kashiwamochi
8
8
  options[:url] ||= url_for
9
9
  options[:as] ||= Kashiwamochi.config.search_key
10
10
  options[:method] ||= :get
11
- options[:html] ||= {}
12
- options[:html].tap do |html|
13
- html[:id] ||= "#{options[:as]}_#{Kashiwamochi.config.form_class}"
14
- html[:class] = [
15
- html[:class] || "#{options[:as]}_#{Kashiwamochi.config.form_class}",
16
- "#{Kashiwamochi.config.form_class}"
17
- ].compact.join(' ')
18
- html[:method] ||= :get
19
- end
11
+
12
+ html_options = options[:html] ||= {}
13
+ html_options[:id] ||= "#{options[:as]}_#{Kashiwamochi.config.form_class}"
14
+ html_options[:class] = [Kashiwamochi.config.form_class, html_options[:class]].compact.join(' ')
20
15
 
21
16
  form_method = options.delete(:form_method) || Kashiwamochi.config.form_method
22
- send(form_method, query, *(args << options), &block)
17
+ __send__(form_method, query, *(args << options), &block)
23
18
  end
24
19
 
25
20
  def search_sort_link_to(query, attribute, *args)
@@ -3,7 +3,7 @@ require 'active_support/core_ext/hash/indifferent_access'
3
3
 
4
4
  module Kashiwamochi
5
5
  class Query
6
- attr_accessor :search_params, :sort_params
6
+ attr_reader :search_params, :sort_params
7
7
 
8
8
  def initialize(attributes = {})
9
9
  @search_params = ActiveSupport::OrderedHash.new.with_indifferent_access
@@ -105,5 +105,9 @@ module Kashiwamochi
105
105
  def persisted?
106
106
  false
107
107
  end
108
+
109
+ def searched?
110
+ !@search_params.empty? || !@sort_params.empty?
111
+ end
108
112
  end
109
113
  end
@@ -1,3 +1,3 @@
1
1
  module Kashiwamochi
2
- VERSION = "0.4.2"
2
+ VERSION = "0.4.3"
3
3
  end
@@ -2,15 +2,37 @@ require 'spec_helper'
2
2
 
3
3
  describe Kashiwamochi::ActionView do
4
4
  describe '#search_form_for' do
5
+ def with_concat_form_for(*args, &block)
6
+ concat helper.search_form_for(*args, &(block || proc {}))
7
+ end
8
+
5
9
  before do
6
10
  @q = Kashiwamochi::Query.new(:name => 'test', :s => 'name desc')
7
- helper.search_form_for @q, :url => {:controller => 'users', :action => 'index'} do |f|
8
- @f = f
11
+ end
12
+
13
+ describe 'instance of' do
14
+ before do
15
+ helper.search_form_for @q, :url => {:controller => 'users', :action => 'index'} do |f|
16
+ @f = f
17
+ end
9
18
  end
19
+ subject { @f }
20
+ it { should be_an_instance_of ActionView::Helpers::FormBuilder }
21
+ end
22
+
23
+ describe 'default id and class' do
24
+ before { @buffer = with_concat_form_for(@q, :url => '/') }
25
+ subject { @buffer }
26
+ it { should match %r(id="q_search") }
27
+ it { should match %r(class="search") }
10
28
  end
11
- subject { @f }
12
29
 
13
- it { should be_an_instance_of ActionView::Helpers::FormBuilder }
30
+ describe 'user id and class' do
31
+ before { @buffer = with_concat_form_for(@q, :url => '/', :html => {:id => 'aaa', :class => 'bbb'}) }
32
+ subject { @buffer }
33
+ it { should match %r(id="aaa") }
34
+ it { should match %r(class="search bbb") }
35
+ end
14
36
  end
15
37
 
16
38
  describe '#search_sort_link_to' do
@@ -90,6 +90,20 @@ describe Kashiwamochi::Query do
90
90
  end
91
91
  end
92
92
 
93
+ describe '#searched?' do
94
+ context 'with query' do
95
+ before { @q = Kashiwamochi::Query.new(:name => 'aira', :s => ["created_at desc"]) }
96
+ subject { @q }
97
+ it { should be_searched }
98
+ end
99
+
100
+ context 'without query' do
101
+ before { @q = Kashiwamochi::Query.new }
102
+ subject { @q }
103
+ it { should_not be_searched }
104
+ end
105
+ end
106
+
93
107
  describe '#to_option' do
94
108
  before { @q = Kashiwamochi::Query.new(:name => 'aira', :s => ["created_at desc"]) }
95
109
  subject { @q.to_option }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kashiwamochi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.4.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-05-02 00:00:00.000000000 Z
12
+ date: 2012-08-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: railties
@@ -154,7 +154,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
154
154
  version: '0'
155
155
  segments:
156
156
  - 0
157
- hash: -2847632178335067109
157
+ hash: -4114840748124176109
158
158
  required_rubygems_version: !ruby/object:Gem::Requirement
159
159
  none: false
160
160
  requirements:
@@ -163,7 +163,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
163
163
  version: '0'
164
164
  segments:
165
165
  - 0
166
- hash: -2847632178335067109
166
+ hash: -4114840748124176109
167
167
  requirements: []
168
168
  rubyforge_project: kashiwamochi
169
169
  rubygems_version: 1.8.21