netzke-basepack 0.7.4 → 0.7.5

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.
Files changed (74) hide show
  1. data/.travis.yml +11 -0
  2. data/CHANGELOG.rdoc +10 -0
  3. data/README.md +36 -2
  4. data/Rakefile +1 -3
  5. data/config/ci/before-travis.sh +28 -0
  6. data/lib/netzke/active_record.rb +10 -8
  7. data/lib/netzke/active_record/attributes.rb +28 -17
  8. data/lib/netzke/active_record/relation_extensions.rb +3 -1
  9. data/lib/netzke/basepack.rb +10 -2
  10. data/lib/netzke/basepack/action_column.rb +6 -8
  11. data/lib/netzke/basepack/data_accessor.rb +11 -174
  12. data/lib/netzke/basepack/data_adapters/abstract_adapter.rb +164 -0
  13. data/lib/netzke/basepack/data_adapters/active_record_adapter.rb +279 -0
  14. data/lib/netzke/basepack/data_adapters/data_mapper_adapter.rb +264 -0
  15. data/lib/netzke/basepack/data_adapters/sequel_adapter.rb +260 -0
  16. data/lib/netzke/basepack/form_panel.rb +3 -3
  17. data/lib/netzke/basepack/form_panel/fields.rb +6 -10
  18. data/lib/netzke/basepack/form_panel/javascripts/form_panel.js +1 -0
  19. data/lib/netzke/basepack/form_panel/services.rb +15 -16
  20. data/lib/netzke/basepack/grid_panel.rb +16 -10
  21. data/lib/netzke/basepack/grid_panel/columns.rb +6 -7
  22. data/lib/netzke/basepack/grid_panel/javascripts/event_handling.js +29 -27
  23. data/lib/netzke/basepack/grid_panel/services.rb +13 -90
  24. data/lib/netzke/basepack/paging_form_panel.rb +3 -3
  25. data/lib/netzke/basepack/query_builder.rb +2 -0
  26. data/lib/netzke/basepack/query_builder/javascripts/query_builder.js +29 -19
  27. data/lib/netzke/basepack/search_panel.rb +6 -3
  28. data/lib/netzke/basepack/search_panel/javascripts/search_panel.js +2 -1
  29. data/lib/netzke/basepack/search_window.rb +2 -1
  30. data/lib/netzke/basepack/version.rb +1 -1
  31. data/lib/netzke/data_mapper.rb +18 -0
  32. data/lib/netzke/data_mapper/attributes.rb +273 -0
  33. data/lib/netzke/data_mapper/combobox_options.rb +11 -0
  34. data/lib/netzke/data_mapper/relation_extensions.rb +38 -0
  35. data/lib/netzke/sequel.rb +18 -0
  36. data/lib/netzke/sequel/attributes.rb +274 -0
  37. data/lib/netzke/sequel/combobox_options.rb +10 -0
  38. data/lib/netzke/sequel/relation_extensions.rb +40 -0
  39. data/netzke-basepack.gemspec +24 -13
  40. data/test/basepack_test_app/Gemfile +33 -8
  41. data/test/basepack_test_app/Gemfile.lock +98 -79
  42. data/test/basepack_test_app/Guardfile +46 -0
  43. data/test/basepack_test_app/app/components/book_grid_with_persistence.rb +3 -0
  44. data/test/basepack_test_app/app/components/extras/book_presentation.rb +10 -3
  45. data/test/basepack_test_app/app/models/address.rb +27 -1
  46. data/test/basepack_test_app/app/models/author.rb +28 -0
  47. data/test/basepack_test_app/app/models/book.rb +43 -0
  48. data/test/basepack_test_app/app/models/book_with_custom_primary_key.rb +22 -0
  49. data/test/basepack_test_app/app/models/role.rb +21 -0
  50. data/test/basepack_test_app/app/models/user.rb +24 -0
  51. data/test/basepack_test_app/config/database.yml.sample +11 -10
  52. data/test/basepack_test_app/config/database.yml.travis +15 -0
  53. data/test/basepack_test_app/config/initializers/data_mapper_logging.rb +3 -0
  54. data/test/basepack_test_app/config/initializers/sequel.rb +26 -0
  55. data/test/basepack_test_app/db/schema.rb +0 -3
  56. data/test/basepack_test_app/features/grid_panel.feature +28 -8
  57. data/test/basepack_test_app/features/grid_sorting.feature +6 -6
  58. data/test/basepack_test_app/features/paging_form_panel.feature +13 -13
  59. data/test/basepack_test_app/features/search_in_grid.feature +31 -31
  60. data/test/basepack_test_app/features/step_definitions/generic_steps.rb +3 -1
  61. data/test/basepack_test_app/features/support/env.rb +17 -4
  62. data/test/basepack_test_app/lib/tasks/travis.rake +7 -0
  63. data/test/basepack_test_app/spec/components/form_panel_spec.rb +2 -2
  64. data/test/basepack_test_app/spec/data_adapter/adapter_spec.rb +68 -0
  65. data/test/basepack_test_app/spec/{active_record → data_adapter}/attributes_spec.rb +12 -4
  66. data/test/basepack_test_app/spec/data_adapter/relation_extensions_spec.rb +125 -0
  67. data/test/basepack_test_app/spec/spec_helper.rb +9 -0
  68. data/test/unit/active_record_basepack_test.rb +1 -1
  69. data/test/unit/grid_panel_test.rb +1 -1
  70. metadata +26 -31
  71. data/app/models/netzke_field_list.rb +0 -261
  72. data/app/models/netzke_model_attr_list.rb +0 -21
  73. data/app/models/netzke_persistent_array_auto_model.rb +0 -57
  74. data/test/basepack_test_app/spec/active_record/relation_extensions_spec.rb +0 -44
@@ -13,11 +13,11 @@ Feature: Grid sorting
13
13
 
14
14
  When I go to the BookGrid test page
15
15
  And I click on column "Title"
16
- And I sleep 1 second
16
+ And I wait for the response from the server
17
17
  Then the grid should have records sorted by "Title"
18
18
 
19
19
  When I click on column "Title"
20
- And I sleep 1 second
20
+ And I wait for the response from the server
21
21
  Then the grid should have records sorted by "Title" desc
22
22
 
23
23
  @javascript
@@ -31,17 +31,17 @@ Feature: Grid sorting
31
31
 
32
32
  When I go to the BookGridWithCustomColumns test page
33
33
  And I click on column "Author first name"
34
- And I sleep 1 second
34
+ And I wait for the response from the server
35
35
  Then the grid should have records sorted by "Author first name"
36
36
 
37
37
  When I click on column "Author first name"
38
- And I sleep 1 second
38
+ And I wait for the response from the server
39
39
  Then the grid should have records sorted by "Author first name" desc
40
40
 
41
41
  When I go to the BookGrid test page
42
42
  And I click on column "Author name"
43
- And I sleep 1 second
43
+ And I wait for the response from the server
44
44
  Then the grid should have records sorted by "Author name"
45
45
  When I click on column "Author name"
46
- And I sleep 1 second
46
+ And I wait for the response from the server
47
47
  Then the grid should have records sorted by "Author name" desc
@@ -23,19 +23,19 @@ Scenario: Paging through records
23
23
  And I wait for the response from the server
24
24
  Then the form should show title: "Getting Things Done"
25
25
 
26
- @javascript
27
- Scenario: Searching
28
- When I go to the BookPagingFormPanel test page
29
- And I press "Search"
30
- And I wait for the response from the server
31
- And I expand combobox "undefined_attr"
32
- And I select "Exemplars" from combobox "undefined_attr"
33
- And I expand combobox "exemplars_operator"
34
- And I select "Less than" from combobox "exemplars_operator"
35
- And I fill in "exemplars_value" with "5"
36
- And I press "Search" within "#book_paging_form_panel__search_form"
37
- And I wait for the response from the server
38
- Then the form should show title: "Getting Things Done"
26
+ #@javascript
27
+ #Scenario: Searching
28
+ #When I go to the BookPagingFormPanel test page
29
+ #And I press "Search"
30
+ #And I wait for the response from the server
31
+ #And I expand combobox "undefined_attr"
32
+ #And I select "Exemplars" from combobox "undefined_attr"
33
+ #And I expand combobox "exemplars_operator"
34
+ #And I select "Less than" from combobox "exemplars_operator"
35
+ #And I fill in "exemplars_value" with "5"
36
+ #And I press "Search" within "#book_paging_form_panel__search_form"
37
+ #And I wait for the response from the server
38
+ #Then the form should show title: "Getting Things Done"
39
39
 
40
40
  @javascript
41
41
  Scenario: I must see total records value
@@ -1,35 +1,35 @@
1
- Feature: Search
2
- In order to value
3
- As a role
4
- I want feature
1
+ #Feature: Search
2
+ #In order to value
3
+ #As a role
4
+ #I want feature
5
5
 
6
- @javascript
7
- Scenario: Search via Search window
8
- Given the following roles exist:
9
- | id | name |
10
- | 1 | admin |
11
- | 2 | superadmin |
12
- | 3 | user |
6
+ #@javascript
7
+ #Scenario: Search via Search window
8
+ #Given the following roles exist:
9
+ #| id | name |
10
+ #| 1 | admin |
11
+ #| 2 | superadmin |
12
+ #| 3 | user |
13
13
 
14
- And the following users exist:
15
- | first_name | last_name | role_id |
16
- | Paul | Bley | 1 |
17
- | Dalai | Lama | 3 |
18
- | Taisha | Abelar | 2 |
19
- | Florinda | Donner | 1 |
14
+ #And the following users exist:
15
+ #| first_name | last_name | role_id |
16
+ #| Paul | Bley | 1 |
17
+ #| Dalai | Lama | 3 |
18
+ #| Taisha | Abelar | 2 |
19
+ #| Florinda | Donner | 1 |
20
20
 
21
- When I go to the UserGrid test page
22
- Then the grid should show 4 records
21
+ #When I go to the UserGrid test page
22
+ #Then the grid should show 4 records
23
23
 
24
- When I press "Search"
25
- And I wait 1 second
26
- And I expand combobox "undefined_attr"
27
- And I select "First name" from combobox "undefined_attr"
28
- And I wait 1 second
29
- And I fill in "first_name_value" with "ai"
30
- And I press "Search" within "#user_grid__search_form"
31
- And I sleep 1 second
32
- Then the grid should show 2 records
24
+ #When I press "Search"
25
+ #And I wait for the response from the server
26
+ #And I expand combobox "undefined_attr"
27
+ #And I select "First name" from combobox "undefined_attr"
28
+ #And I wait for the response from the server
29
+ #And I fill in "first_name_value" with "ai"
30
+ #And I press "Search" within "#user_grid__search_form"
31
+ #And I wait for the response from the server
32
+ #Then the grid should show 2 records
33
33
 
34
34
  # When I press "Search"
35
35
  # And I follow "+"
@@ -37,7 +37,7 @@ Feature: Search
37
37
  # And I select "First name" from combobox "undefined_attr"
38
38
  # And I fill in "first_name_value" with "in"
39
39
  # And I press "Search" within "#user_grid__search_form"
40
- # And I sleep 1 second
40
+ # And I wait for the response from the server
41
41
  # Then the grid should show 3 records
42
42
 
43
43
  # Search on association column not supported yet
@@ -45,5 +45,5 @@ Feature: Search
45
45
  # And I fill in "Role name like:" with "adm"
46
46
  # And I fill in "First name like:" with ""
47
47
  # And I press "Search" within "#user_grid__search_form"
48
- # And I sleep 1 second
49
- # Then the grid should show 3 records
48
+ # And I wait for the response from the server
49
+ # Then the grid should show 3 records
@@ -15,7 +15,9 @@ When /I (?:sleep|wait) (\d+) (\w+)/ do |amount, unit|
15
15
  end
16
16
 
17
17
  When /^I wait for the response from the server$/ do
18
- page.wait_until{ page.driver.browser.execute_script("return !Netzke.ajaxIsLoading()") }
18
+ sleep 0.5
19
+ page.wait_until{ page.driver.browser.execute_script("return !(Netzke.ajaxIsLoading() || Ext.Ajax.isLoading())") }
20
+ sleep 0.5
19
21
  end
20
22
 
21
23
  When /^I go forward one page$/ do
@@ -23,9 +23,14 @@ require 'capybara/cucumber'
23
23
  require 'capybara/session'
24
24
  # require 'cucumber/rails/capybara_javascript_emulation' # Lets you click links with onclick javascript handlers without using @culerity or @javascript
25
25
 
26
- # Capybara.register_driver :selenium do |app|
27
- # Capybara::Driver::Selenium.new(app, {:profile => 'selenium' } )
28
- # end
26
+ # resynchronize after ajax call
27
+ # from README at (https://github.com/jnicklas/capybara)
28
+ Capybara.register_driver :selenium do |app|
29
+ Capybara::Selenium::Driver.new(app, {:resynchronize => true } )
30
+ end
31
+
32
+ # wait a bit longer (default 2s)
33
+ Capybara.default_wait_time = 5
29
34
 
30
35
  # Capybara defaults to XPath selectors rather than Webrat's default of CSS3. In
31
36
  # order to ease the transition to Capybara we set the default here. If you'd
@@ -56,13 +61,21 @@ ActionController::Base.allow_rescue = false
56
61
  # after each scenario, which can lead to hard-to-debug failures in
57
62
  # subsequent scenarios. If you do this, we recommend you create a Before
58
63
  # block that will explicitly put your database in a known state.
59
- Cucumber::Rails::World.use_transactional_fixtures = true
60
64
  # How to clean your database when transactions are turned off. See
61
65
  # http://github.com/bmabey/database_cleaner for more info.
62
66
  if defined?(ActiveRecord::Base)
63
67
  begin
64
68
  require 'database_cleaner'
65
69
  DatabaseCleaner.strategy = :truncation
70
+ Cucumber::Rails::World.use_transactional_fixtures = true
71
+ rescue LoadError => ignore_if_database_cleaner_not_present
72
+ end
73
+ end
74
+
75
+ if defined?(DataMapper::Resource)
76
+ begin
77
+ require 'database_cleaner'
78
+ DatabaseCleaner[:data_mapper].strategy = :truncation
66
79
  rescue LoadError => ignore_if_database_cleaner_not_present
67
80
  end
68
81
  end
@@ -0,0 +1,7 @@
1
+ task :travis do
2
+ ["rake spec", "rake cucumber"].each do |cmd|
3
+ puts "Starting to run #{cmd}..."
4
+ system("export DISPLAY=:99.0 && bundle exec #{cmd}")
5
+ raise "#{cmd} failed!" unless $?.exitstatus == 0
6
+ end
7
+ end
@@ -16,7 +16,7 @@ describe Netzke::Basepack::FormPanel do
16
16
  form = Netzke::Basepack::FormPanel.new(:model => 'User', :items => [:first_name, :created_at, :role__name])
17
17
 
18
18
  form.fields[:first_name][:xtype].should == :textfield
19
- form.fields[:created_at][:xtype].should == :datetimefield
19
+ form.fields[:created_at][:xtype].should == :xdatetime
20
20
  form.fields[:role__name][:xtype].should == :netzkeremotecombo
21
21
  end
22
22
 
@@ -50,4 +50,4 @@ describe Netzke::Basepack::FormPanel do
50
50
  form.items[3][:name].should == "updated_at"
51
51
  end
52
52
 
53
- end
53
+ end
@@ -0,0 +1,68 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ if defined? DataMapper::Resource
4
+
5
+ Book.class_eval do
6
+
7
+ def self.title_like_jou
8
+ all(:title.like => "Jou%")
9
+ end
10
+
11
+ def self.author_name_like_he
12
+ all(Author.last_name.like => "He%")
13
+ end
14
+ end
15
+
16
+ elsif defined? Sequel::Model
17
+
18
+ Book.class_eval do
19
+ def_dataset_method(:title_like_jou) do
20
+ where(:title.like("Jou%"))
21
+ end
22
+
23
+ def_dataset_method(:author_name_like_he) do
24
+ eager_graph(:author).where(:author__name.like("He%"))
25
+ end
26
+ end
27
+
28
+ else
29
+
30
+ Book.class_eval do
31
+ scope :title_like_jou, where("title LIKE 'Jou%'")
32
+ scope :author_name_like_he, joins(:author).where("authors.last_name LIKE 'He%'")
33
+ end
34
+
35
+ end
36
+
37
+ adapter_class=Netzke::Basepack::DataAdapters::AbstractAdapter.adapter_class(Book)
38
+ describe adapter_class do
39
+
40
+ before :all do
41
+ castaneda = Factory(:author, {:first_name => "Carlos", :last_name => "Castaneda"})
42
+ hesse = Factory(:author, {:first_name => "Herman", :last_name => "Hesse"})
43
+
44
+ Factory(:book, {:title => "Journey to Ixtlan", :author => castaneda})
45
+ Factory(:book, {:title => "The Tales of Power", :author => castaneda})
46
+ Factory(:book, {:title => "The Art of Dreaming", :author => castaneda})
47
+ Factory(:book, {:title => "Steppenwolf", :author => hesse})
48
+ Factory(:book, {:title => "Demian", :author => hesse})
49
+ Factory(:book, {:title => "Narciss and Goldmund", :author => hesse})
50
+
51
+ @adapter = adapter_class.new(Book)
52
+ end
53
+
54
+ it "should return a hash fk to model" do
55
+ @adapter.hash_fk_model.should == {:author_id => :author}
56
+ end
57
+
58
+ it "should report correct record count when filters are specified" do
59
+ @adapter.count_records({:filter=>ActiveSupport::JSON.encode([{'field' => 'title', 'value' => 'Journ', 'type' => 'string', 'comparsion' => 'matches' }])}).should == 1
60
+ end
61
+
62
+ it "should report correct record count when filters on association columns are specified" do
63
+ @adapter.count_records({:filter=>ActiveSupport::JSON.encode([{'field' => 'author__last_name', 'value' => 'Cast', 'type' => 'string', 'comparsion' => 'matches' }])},[{:name => 'author__last_name'}]).should == 3
64
+ end
65
+
66
+ # TODO: test scope and query for assoc columns and non-assoc columns
67
+
68
+ end
@@ -2,18 +2,18 @@ require File.dirname(__FILE__) + '/../spec_helper'
2
2
 
3
3
  describe Netzke::ActiveRecord::Attributes do
4
4
  it "should return Netzke attributes in natural order" do
5
- User.send(:netzke_attrs_in_natural_order).map{ |a| a[:name] }.should == %w(id first_name last_name role__name created_at updated_at)
5
+ User.send(:netzke_attrs_in_natural_order).map{ |a| a[:name] }.should =~ %w(id first_name last_name role__name created_at updated_at)
6
6
  end
7
7
 
8
8
  it "should return exposed Netzke attributes" do
9
9
  class UserExt < User
10
10
  netzke_expose_attributes :first_name, :created_at
11
11
  end
12
- UserExt.netzke_attributes.map{ |a| a[:name] }.should == %w(id first_name created_at)
12
+ UserExt.netzke_attributes.map{ |a| a[:name] }.should =~ %w(id first_name created_at)
13
13
  end
14
14
 
15
15
  it "should return Netzke attributes including an association attribute represented by a virtual method" do
16
- Book.netzke_attributes.map{ |a| a[:name] }.should == %w(id author__name title exemplars digitized notes tags rating created_at updated_at)
16
+ Book.netzke_attributes.map{ |a| a[:name] }.should =~ %w(id author__name title exemplars digitized notes tags rating created_at updated_at last_read_at published_on)
17
17
  Book.netzke_attributes.detect{ |a| a[:name] == "author__name" }[:attr_type].should == :string
18
18
  end
19
19
 
@@ -27,6 +27,7 @@ describe Netzke::ActiveRecord::Attributes do
27
27
  author = Factory(:author)
28
28
  book = Factory(:book, :author => author)
29
29
  book.set_value_for_attribute({:name => :author__first_name, :nested_attribute => true}, "Carlitos")
30
+ author.reload if defined? Sequel::Model
30
31
  author.first_name.should == "Carlitos"
31
32
  end
32
33
 
@@ -40,9 +41,16 @@ describe Netzke::ActiveRecord::Attributes do
40
41
 
41
42
  it "should be possible to change address of a user (has_one association) via association attribute without specifying :nested_attribute => true" do
42
43
  address = Factory(:address)
43
- user = Factory(:user, :address => address)
44
+ user = Factory(:user)
45
+ user.address = address
44
46
  user.set_value_for_attribute({:name => :address__city}, "Hidden Treasures")
45
47
  address.city.should == "Hidden Treasures"
46
48
  end
47
49
 
50
+ it "should consider netzke_attributes, normalize date formats and niftify on #netzke_json" do
51
+ Time.zone = 'UTC'
52
+ author = Factory(:author, :created_at => Time.zone.at(0), :updated_at => Time.zone.at(0))
53
+ author.netzke_json.should == "{\"id\":#{author.id},\"firstName\":\"Carlos\",\"lastName\":\"Castaneda\",\"createdAt\":\"1970-01-01 00:00:00\",\"updatedAt\":\"1970-01-01 00:00:00\",\"name\":\"Castaneda, Carlos\"}"
54
+ end
55
+
48
56
  end
@@ -0,0 +1,125 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ if defined? DataMapper::Resource
4
+
5
+ User.class_eval do
6
+
7
+ def self.role_id_gt_7
8
+ all(:role_id.gt => 7)
9
+ end
10
+
11
+ def self.role_id_gt param
12
+ all(:role_id.gt => param)
13
+ end
14
+ end
15
+
16
+ describe Netzke::DataMapper::RelationExtensions do
17
+ it "should accept different options in extend_with" do
18
+ # Preparations
19
+ 10.times do |i|
20
+ Factory(:user, :first_name => "First Name #{i}", :role_id => i)
21
+ end
22
+
23
+ # Tests
24
+
25
+ User.all.extend_with(:role_id_gt_7).count.should == 2
26
+
27
+ User.all.extend_with(:role_id_gt, 2).count.should == 7
28
+
29
+ User.all.extend_with([:role_id_gt, 3]).count.should == 6
30
+
31
+ User.all.extend_with(:role_id => 5).first.first_name.should == "First Name 5"
32
+
33
+ User.all(:role_id.lt => 7).extend_with(lambda{ |relation| relation.all( :role_id.gt => 4)}).count.should == 2
34
+
35
+ #Not supported in DM
36
+ lambda { User.all.extend_with("select * from users where role_id > 6") }.should raise_error NotImplementedError
37
+ lambda { User.all.extend_with(["role_id >= ?", 5]).count }.should raise_error NotImplementedError
38
+ end
39
+ end
40
+
41
+ elsif defined? Sequel::Model
42
+
43
+ User.class_eval do
44
+
45
+ def_dataset_method(:role_id_gt_7) do
46
+ where{role_id > 7}
47
+ end
48
+
49
+ def_dataset_method(:role_id_gt) do |p|
50
+ where{role_id > p}
51
+ end
52
+
53
+ end
54
+
55
+ describe Netzke::Sequel::RelationExtensions do
56
+ it "should accept different options in extend_with" do
57
+ # Preparations
58
+ 10.times do |i|
59
+ Factory(:user, :first_name => "First Name #{i}", :role_id => i)
60
+ end
61
+
62
+ # Tests
63
+
64
+ User.extend_with(:role_id_gt_7).count.should == 2
65
+ User.extend_with(:role_id_gt, 2).count.should == 7
66
+ User.extend_with([:role_id_gt, 3]).count.should == 6
67
+ User.extend_with(:role_id => 5).first.first_name.should == "First Name 5"
68
+ User.where{role_id < 7}.extend_with(lambda{ |dataset| dataset.where{ role_id > 4}}).count.should == 2
69
+ User.extend_with("role_id > 6").count.should == 3
70
+ User.extend_with(["role_id >= ?", 5]).count.should == 5
71
+
72
+ end
73
+ end
74
+
75
+ else
76
+
77
+ User.class_eval do
78
+ scope :role_id_gt_7, where("role_id > 7")
79
+ scope :role_id_gt, lambda { |param| where("role_id > ?", param) }
80
+ end
81
+
82
+ describe Netzke::ActiveRecord::RelationExtensions do
83
+ it "should accept different options in extend_with" do
84
+ # Preparations
85
+ 10.times do |i|
86
+ Factory(:user, :first_name => "First Name #{i}", :role_id => i)
87
+ end
88
+
89
+ # Tests
90
+ User.where({}).extend_with(["role_id >= ?", 5]).count.should == 5
91
+
92
+ User.where({}).extend_with(:role_id_gt_7).count.should == 2
93
+
94
+ User.where({}).extend_with(:role_id_gt, 2).count.should == 7
95
+
96
+ User.where({}).extend_with([:role_id_gt, 3]).count.should == 6
97
+
98
+ User.where({}).extend_with(:role_id => 5).first.first_name.should == "First Name 5"
99
+
100
+ User.where(["role_id < ?", 7]).extend_with(lambda{ |relation| relation.where(["role_id > ?", 4]) }).count.should == 2
101
+
102
+ #User.where({}).extend_with("select * from users where role_id > 6").all.size.should == 3
103
+
104
+ end
105
+ end
106
+
107
+
108
+ end
109
+
110
+
111
+ #it "should be extendable with extend_with_netzke_conditions" do
112
+ ## Preparations
113
+ #roles = [Factory(:role, :name => "admin"), Factory(:role, :name => "user"), Factory(:role, :name => "superadmin")]
114
+
115
+ ## 3 users of each role
116
+ #9.times do |i|
117
+ #Factory(:user, :role_id => roles[i%3].id)
118
+ #end
119
+
120
+ ## Tests
121
+ ## User.where({}).extend_with_netzke_conditions(:role_id__eq => roles.last.id).count.should == 3
122
+ ## User.where({}).extend_with_netzke_conditions(:role_name__eq => "admin").count.should == 3
123
+ ## User.where({}).extend_with_netzke_conditions(:role__name__like => "%admin%").count.should == 6
124
+ #end
125
+