will_filter 3.1.2 → 3.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. data/.gitignore +12 -1
  2. data/.rspec +2 -1
  3. data/Gemfile.lock +1 -1
  4. data/app/assets/stylesheets/will_filter/buttons.css.scss +1 -1
  5. data/app/assets/stylesheets/will_filter/calendar.css.scss +54 -7
  6. data/app/assets/stylesheets/will_filter/exporter.css.scss +40 -17
  7. data/app/assets/stylesheets/will_filter/filter.css.scss +169 -144
  8. data/app/controllers/will_filter/exporter_controller.rb +3 -10
  9. data/app/views/will_filter/filter/_condition.html.erb +8 -10
  10. data/app/views/will_filter/filter/_conditions.html.erb +41 -37
  11. data/app/views/will_filter/filter/_container.html.erb +28 -22
  12. data/app/views/will_filter/filter/containers/_boolean.html.erb +1 -1
  13. data/config/will_filter/config.yml +1 -1
  14. data/lib/generators/will_filter/templates/config.yml +1 -1
  15. data/lib/will_filter/version.rb +1 -1
  16. data/spec/config/config_spec.rb +14 -0
  17. data/spec/extensions/active_record_extension_spec.rb +40 -0
  18. data/spec/fake_app.rb +57 -0
  19. data/spec/spec_helper.rb +24 -23
  20. data/test/.DS_Store +0 -0
  21. data/test/dummy/.DS_Store +0 -0
  22. data/test/dummy/config/will_filter/config.yml +1 -1
  23. data/test/dummy/db/migrate/20110924023807_create_will_filter_filters.rb +19 -0
  24. metadata +38 -60
  25. data/test/dummy/.sass-cache/f9cb1ef521115be73f1c61d3d5d64f66c947af63/buttons.css.scssc +0 -0
  26. data/test/dummy/.sass-cache/f9cb1ef521115be73f1c61d3d5d64f66c947af63/calendar.css.scssc +0 -0
  27. data/test/dummy/.sass-cache/f9cb1ef521115be73f1c61d3d5d64f66c947af63/exporter.css.scssc +0 -0
  28. data/test/dummy/.sass-cache/f9cb1ef521115be73f1c61d3d5d64f66c947af63/filter.css.scssc +0 -0
  29. data/test/dummy/test/functional/welcome_controller_test.rb +0 -9
  30. data/test/dummy/test/unit/helpers/welcome_helper_test.rb +0 -4
  31. data/test/fixtures/will_filter/filters.yml +0 -11
  32. data/test/functional/will_filter/calendar_controller_test.rb +0 -9
  33. data/test/functional/will_filter/exporter_controller_test.rb +0 -9
  34. data/test/functional/will_filter/filter_controller_test.rb +0 -9
  35. data/test/integration/navigation_test.rb +0 -10
  36. data/test/unit/helpers/will_filter/calendar_helper_test.rb +0 -6
  37. data/test/unit/helpers/will_filter/exporter_helper_test.rb +0 -6
  38. data/test/unit/helpers/will_filter/filter_helper_test.rb +0 -6
  39. data/test/unit/will_filter/filter_test.rb +0 -9
@@ -1,56 +1,60 @@
1
- <%= hidden_field_tag(:wf_id, wf_filter.id) %>
2
- <%= hidden_field_tag(:wf_type, wf_filter.class.name) %>
3
- <%= hidden_field_tag(:wf_dirty, "false") %>
4
- <%= hidden_field_tag(:wf_submitted, "false") %>
5
- <%= hidden_field_tag(:wf_name, wf_filter.name) %>
6
- <%= hidden_field_tag(:wf_model, wf_filter.model_class_name) %>
7
- <%= hidden_field_tag(:wf_export_format, "") %>
8
- <%= hidden_field_tag(:wf_export_fields, "") %>
9
-
1
+ <div style="margin:0;padding:0;display:inline">
2
+ <%= hidden_field_tag(:wf_id, wf_filter.id) %>
3
+ <%= hidden_field_tag(:wf_type, wf_filter.class.name) %>
4
+ <%= hidden_field_tag(:wf_dirty, "false") %>
5
+ <%= hidden_field_tag(:wf_submitted, "false") %>
6
+ <%= hidden_field_tag(:wf_name, wf_filter.name) %>
7
+ <%= hidden_field_tag(:wf_model, wf_filter.model_class_name) %>
8
+ <%= hidden_field_tag(:wf_export_format, "") %>
9
+ <%= hidden_field_tag(:wf_export_fields, "") %>
10
+ </div>
11
+
10
12
  <div class="header">
11
13
  <% if wf_filter.show_save_options? %>
12
- <div style="float:right;">
13
- <%=link_to_function("<span>Save As New...</span>".html_safe, "wfFilter.saveFilter()", :class => "wf_grey_button wf_pcb") %>
14
- <%=link_to_function("<span>Update</span>".html_safe, "wfFilter.updateFilter()", :class => "wf_grey_button wf_pcb") %>
15
- <%=link_to_function("<span>Delete</span>".html_safe, "wfFilter.deleteFilter()", :class => "wf_grey_button wf_pcb") %>
14
+ <div class="end">
15
+ <%=link_to_function("<span>Save As New...</span>".html_safe, "wfFilter.saveFilter()", :class => "wf_grey_button wf_pcb") %>
16
+ <%=link_to_function("<span>Update</span>".html_safe, "wfFilter.updateFilter()", :class => "wf_grey_button wf_pcb") %>
17
+ <%=link_to_function("<span>Delete</span>".html_safe, "wfFilter.deleteFilter()", :class => "wf_grey_button wf_pcb") %>
16
18
  <% if wf_filter.show_export_options? %>
17
19
  <%=link_to_function("<span>Export Data...</span>".html_safe, "wfExporter.show(this)", :class => "wf_grey_button wf_pcb") %>
18
20
  <% end %>
19
- </div>
21
+ </div>
20
22
  <% end %>
21
- <div style="font-weight:bold; font-size:18px;">
23
+ <div>
22
24
  <% unless wf_filter.saved_filters.empty? %>
23
25
  <%= select_tag(:wf_key, options_for_select(wf_filter.saved_filters, wf_filter.key), {:onChange=>"wfFilter.loadSavedFilter()"}) %>
24
26
  <% end %>
25
- </div>
27
+ </div>
26
28
  </div>
27
29
 
28
30
  <div class="body">
31
+
29
32
  <% if wf_filter.errors[:filter] %>
30
33
  <div class="wf_filter_error">
31
34
  <%= wf_filter.errors[:filter] %>
32
35
  </div>
33
36
  <% end %>
34
37
 
35
- <div style="padding:5px">
36
- Match <%= select_tag(:wf_match, options_for_select(wf_filter.match_options, wf_filter.match), {:onChange=>"wfFilter.markDirty()"}) %>
37
- of the following conditions:
38
- </div>
39
-
40
- <% if wf_filter.size == 0 %>
41
- <div style="font-style:italic; padding:5px; color: black">
42
- You haven't added any filter conditions, so all of the results were returned.
43
- Use the "Add" button in the bottom left corner to add a new condition or select
44
- a predefined filter from a drop-down list above.
45
- </div>
46
- <% else %>
47
- <table class="table" cellpadding="0" cellspacing="0">
48
- <%
49
- 0.upto(wf_filter.size-1) do |index|
50
- condition = wf_filter.condition_at(index)
51
- %>
52
- <%= render :partial => "/will_filter/filter/condition", :locals => {:wf_filter => wf_filter, :condition => condition, :index => index}%>
53
- <% end %>
54
- </table>
55
- <% end %>
38
+ <div class="filter_match_type">
39
+ Match <%= select_tag(:wf_match, options_for_select(wf_filter.match_options, wf_filter.match), {:onChange=>"wfFilter.markDirty()"}) %>
40
+ of the following conditions:
41
+ </div>
42
+
43
+ <% if wf_filter.size == 0 %>
44
+ <div class="no_filter_hint">
45
+ You haven't added any filter conditions, so all of the results were returned.
46
+ Use the "Add" button in the bottom left corner to add a new condition or select
47
+ a predefined filter from a drop-down list above.
48
+ </div>
49
+ <% else %>
50
+ <table class="table" cellpadding="0" cellspacing="0">
51
+ <%
52
+ 0.upto(wf_filter.size-1) do |index|
53
+ condition = wf_filter.condition_at(index)
54
+ %>
55
+ <%= render :partial => "/will_filter/filter/condition", :locals => {:wf_filter => wf_filter, :condition => condition, :index => index}%>
56
+ <% end %>
57
+ </table>
58
+ <% end %>
59
+
56
60
  </div>
@@ -2,30 +2,36 @@
2
2
 
3
3
  <%= form_tag({}, {:method => :get, :name=>'wf_form', :id => 'wf_form', :class => 'wf_form' }) do %>
4
4
  <div class="wf_container">
5
- <div id="wf_filter_conditions" class="conditions">
6
- <%= render :partial=> "/will_filter/filter/conditions", :locals => {:wf_filter => wf_filter} %>
5
+ <div id="wf_filter_conditions" class="conditions">
6
+ <%= render :partial=> "/will_filter/filter/conditions", :locals => {:wf_filter => wf_filter} %>
7
+ </div>
8
+
9
+ <div class="footer">
10
+ <div class="actions">
11
+ <small>
12
+ <%=link_to_function("Toggle Conditions", "wfFilter.toggleDebugger()") %>
13
+ </small>
14
+ &nbsp;&nbsp;
15
+ Order:
16
+ <%= select_tag(:wf_order, options_for_select(wf_filter.condition_options, wf_filter.order), {:onChange=>"markDirty()"}) %>
17
+ <%= select_tag(:wf_order_type, options_for_select(wf_filter.order_type_options, wf_filter.order_type), {:onChange=>"markDirty()"}) %>
18
+ Per Page:
19
+ <%= select_tag(:wf_per_page, options_for_select(wf_filter.per_page_options, wf_filter.per_page.to_s), {:onChange=>"markDirty()"}) %>
20
+ &nbsp;&nbsp;
21
+ <%=link_to_function("<span>Submit Filter</span>".html_safe, "wfFilter.submit()", :class => "wf_grey_button wf_pcb") %>
7
22
  </div>
8
-
9
- <div class="footer">
10
- <div class="actions">
11
- <%=link_to_function("Toggle Conditions", "wfFilter.toggleDebugger()", :style=>"font-size:9px") %>
12
- &nbsp;&nbsp;
13
- Order:
14
- <%= select_tag(:wf_order, options_for_select(wf_filter.condition_options, wf_filter.order), {:onChange=>"markDirty()"}) %>
15
- <%= select_tag(:wf_order_type, options_for_select(wf_filter.order_type_options, wf_filter.order_type), {:onChange=>"markDirty()"}) %>
16
- Per Page:
17
- <%= select_tag(:wf_per_page, options_for_select(wf_filter.per_page_options, wf_filter.per_page.to_s), {:onChange=>"markDirty()"}) %>
18
- &nbsp;&nbsp;<%=link_to_function("<span>Submit Filter</span>".html_safe, "wfFilter.submit()", :class => "wf_grey_button wf_pcb") %>
19
- </div>
20
- <div>
21
- <%=link_to_function("<span>+ Add</span>".html_safe, "wfFilter.addCondition()", :class => "wf_grey_button wf_pcb") %>
22
- <%=link_to_function("<span>- Clear</span>".html_safe, "wfFilter.removeAllConditions()", :class => "wf_grey_button wf_pcb") %>
23
- &nbsp;&nbsp;<span id="wf_loader" class="spinner" style="display:none;"><%=image_tag "will_filter/spinner.gif", {:style=>"vertical-align:middle"} %> Loading...</span>
24
- </div>
23
+ <div>
24
+ <%=link_to_function("<span>+ Add</span>".html_safe, "wfFilter.addCondition()", :class => "wf_grey_button wf_pcb") %>
25
+ <%=link_to_function("<span>- Clear</span>".html_safe, "wfFilter.removeAllConditions()", :class => "wf_grey_button wf_pcb") %>
26
+ &nbsp;&nbsp;
27
+ <span id="wf_loader" class="spinner" style="display:none;">
28
+ <%=image_tag "will_filter/spinner.gif" %> Loading...
29
+ </span>
25
30
  </div>
31
+ </div>
26
32
 
27
- <div id="wf_debugger" class="debugger" style="display:none;">
28
- <%= raw(wf_filter.debug_sql_conditions) %>
29
- </div>
33
+ <div id="wf_debugger" class="debugger" style="display:none;">
34
+ <%= raw(wf_filter.debug_sql_conditions) %>
35
+ </div>
30
36
  </div>
31
37
  <% end %>
@@ -1,4 +1,4 @@
1
- <div style='vertical-align:middle; text-align:left; padding-top:4px;'>
1
+ <div class="boolean_container">
2
2
  <%=radio_button_tag("wf_v#{index}_0", '1', (container.value == '1'), :style => 'width:20px', :onChange => 'wfFilter.fieldChanged(this)')%> True
3
3
  &nbsp;&nbsp;
4
4
  <%=radio_button_tag("wf_v#{index}_0", '0', (container.value == '0'), :style => 'width:20px', :onChange => 'wfFilter.fieldChanged(this)')%> False
@@ -12,7 +12,7 @@
12
12
  defaults: &defaults
13
13
  effects_options:
14
14
  enabled: false
15
- script_path: "/will_filter/javascripts/will_filter_prototype_effects.js"
15
+ script_path: "will_filter/filter_prototype_effects.js"
16
16
 
17
17
  save_options:
18
18
  enabled: true
@@ -12,7 +12,7 @@
12
12
  defaults: &defaults
13
13
  effects_options:
14
14
  enabled: false
15
- script_path: "/will_filter/javascripts/will_filter_prototype_effects.js"
15
+ script_path: "will_filter/filter_prototype_effects.js"
16
16
 
17
17
  save_options:
18
18
  enabled: true
@@ -22,5 +22,5 @@
22
22
  #++
23
23
 
24
24
  module WillFilter
25
- VERSION = "3.1.2"
25
+ VERSION = "3.1.3"
26
26
  end
@@ -0,0 +1,14 @@
1
+ require File.expand_path('../spec_helper', File.dirname(__FILE__))
2
+
3
+ describe WillFilter::Config do
4
+ subject { WillFilter::Config }
5
+ describe 'operator_order' do
6
+ context 'by default' do
7
+ its(:config) {should_not == nil}
8
+ its(:containers) {should_not == nil}
9
+ its(:data_types) {should_not == nil}
10
+ its(:operators) {should_not == nil}
11
+ its(:operator_order) {should_not == nil}
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,40 @@
1
+ require File.expand_path('../spec_helper', File.dirname(__FILE__))
2
+
3
+ describe WillFilter::ActiveRecordExtension do
4
+ describe '#filter' do
5
+ before :all do
6
+ 5.times {|i| User.create(:first_name => "User #{i}")}
7
+ end
8
+
9
+ context "filtering with no params" do
10
+ it "should return all of the results" do
11
+ User.filter(:params => {}).total_count.should == User.count
12
+ end
13
+ end
14
+
15
+ context "filtering with is operator" do
16
+ it "should return a single result" do
17
+ User.filter(:params => {:wf_c0 => "first_name", :wf_o0 => "is", :wf_v0_0 => "User 1"}).total_count.should == 1
18
+ end
19
+ end
20
+
21
+ context "filtering with like operator" do
22
+ it "should return all matched results" do
23
+ User.filter(:params => {:wf_c0 => "first_name", :wf_o0 => "contains", :wf_v0_0 => "User"}).total_count.should == User.count
24
+ end
25
+ end
26
+
27
+ context "filtering with ends_with operator" do
28
+ it "should return all matched results" do
29
+ User.filter(:params => {:wf_c0 => "first_name", :wf_o0 => "ends_with", :wf_v0_0 => "4"}).total_count.should == 1
30
+ end
31
+ end
32
+
33
+ context "filtering with starts_with operator" do
34
+ it "should return all matched results" do
35
+ User.filter(:params => {:wf_c0 => "first_name", :wf_o0 => "starts_with", :wf_v0_0 => "U"}).total_count.should == User.count
36
+ end
37
+ end
38
+
39
+ end
40
+ end
data/spec/fake_app.rb ADDED
@@ -0,0 +1,57 @@
1
+ require 'active_record'
2
+ require 'action_controller/railtie'
3
+ require 'action_view/railtie'
4
+
5
+ # database
6
+ ActiveRecord::Base.configurations = {'test' => {:adapter => 'sqlite3', :database => ':memory:'}}
7
+ ActiveRecord::Base.establish_connection('test')
8
+
9
+ # config
10
+ app = Class.new(Rails::Application)
11
+ app.config.secret_token = "3b7cd727ee24e8444053437c36cc66c4"
12
+ app.config.session_store :cookie_store, :key => "_myapp_session"
13
+ app.config.active_support.deprecation = :log
14
+ app.initialize!
15
+
16
+ # routes
17
+ app.routes.draw do
18
+ resources :users
19
+ end
20
+
21
+ # models
22
+ class User < ActiveRecord::Base
23
+ has_many :events
24
+ has_many :events_users
25
+ end
26
+ class Event < ActiveRecord::Base
27
+ belongs_to :user, :class_name => 'User', :foreign_key => :creator_id
28
+ has_many :event_users
29
+ end
30
+ class EventUser < ActiveRecord::Base
31
+ belongs_to :event
32
+ belongs_to :user
33
+ end
34
+
35
+ # controllers
36
+ class ApplicationController < ActionController::Base; end
37
+ class UsersController < ApplicationController
38
+ def index
39
+ @users = User.filter(:params => params)
40
+ render :inline => <<-ERB
41
+ <%= will_filter_tag(@users) %>
42
+ ERB
43
+ end
44
+ end
45
+
46
+ # helpers
47
+ Object.const_set(:ApplicationHelper, Module.new)
48
+
49
+ #migrations
50
+ class CreateAllTables < ActiveRecord::Migration
51
+ def self.up
52
+ Dir["#{File.dirname(__FILE__)}/../test/dummy/db/migrate/*.rb"].each do |f|
53
+ require f
54
+ f.split("/").last.gsub('.rb', '').split('_')[1..-1].join('_').camelcase.constantize.up
55
+ end
56
+ end
57
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,27 +1,28 @@
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}
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rails'
4
+ require 'kaminari'
5
+ require 'database_cleaner'
6
+ require 'will_filter'
9
7
 
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
8
+ # Ensure we use 'syck' instead of 'psych' in 1.9.2
9
+ # RubyGems >= 1.5.0 uses 'psych' on 1.9.2, but
10
+ # Psych does not yet support YAML 1.1 merge keys.
11
+ # Merge keys is often used in mongoid.yml
12
+ # See: http://redmine.ruby-lang.org/issues/show/4300
13
+ if RUBY_VERSION >= '1.9.2'
14
+ YAML::ENGINE.yamler = 'syck'
15
+ end
16
+ require File.join(File.dirname(__FILE__), 'fake_app')
19
17
 
20
- # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
21
- config.fixture_path = "#{::Rails.root}/spec/fixtures"
18
+ require 'rspec/rails'
19
+ # Requires supporting files with custom matchers and macros, etc,
20
+ # in ./support/ and its subdirectories.
21
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
22
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
23
+ RSpec.configure do |config|
24
+ config.mock_with :rr
25
+ config.before :all do
26
+ CreateAllTables.up unless ActiveRecord::Base.connection.table_exists? 'users'
27
+ end
27
28
  end
data/test/.DS_Store CHANGED
Binary file
data/test/dummy/.DS_Store CHANGED
Binary file
@@ -12,7 +12,7 @@
12
12
  defaults: &defaults
13
13
  effects_options:
14
14
  enabled: false
15
- script_path: "/will_filter/javascripts/will_filter_prototype_effects.js"
15
+ script_path: "will_filter/filter_prototype_effects.js"
16
16
 
17
17
  save_options:
18
18
  enabled: true
@@ -0,0 +1,19 @@
1
+ class CreateWillFilterFilters < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :will_filter_filters do |t|
4
+ t.string :type
5
+ t.string :name
6
+ t.text :data
7
+ t.integer :user_id
8
+ t.string :model_class_name
9
+
10
+ t.timestamps
11
+ end
12
+
13
+ add_index :will_filter_filters, [:user_id]
14
+ end
15
+
16
+ def self.down
17
+ drop_table :will_filter_filters
18
+ end
19
+ end