netzke-basepack 0.7.4 → 0.7.5

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -1,57 +0,0 @@
1
- require 'acts_as_list'
2
- class NetzkePersistentArrayAutoModel < ActiveRecord::Base
3
- set_table_name "netzke_temp_table"
4
- connection.create_table(table_name){} if !connection.table_exists?(table_name)
5
-
6
- acts_as_list
7
- default_scope :order => "position"
8
-
9
- cattr_accessor :config
10
-
11
- def self.all_columns
12
- self.all.map{ |c| c.attributes.reject{ |k,v| k == 'id' || k == 'position' } }
13
- end
14
-
15
- # Configuration
16
- def self.configure(config)
17
- self.config = config
18
- if NetzkePreference.first(:conditions => {:name => "netzke_persistent_array_refresh_token"}).try(:value) != refresh_token || !connection.table_exists?(table_name)
19
- rebuild_table#(:columns => config[:columns], :initial_data => config[:initial_data])
20
- end
21
- NetzkePreference.find_or_create_by_name("netzke_persistent_array_refresh_token").update_attribute(:value, refresh_token)
22
- end
23
-
24
- def self.rebuild_table#(config)
25
- connection.drop_table(table_name) if connection.table_exists?(table_name)
26
- # create the table with the fields
27
- self.connection.create_table(table_name) do |t|
28
- config[:columns].each do |c|
29
- c = c.dup # to make next line shorter
30
- t.column c.delete(:name), c.delete(:type), c
31
- end
32
- end
33
-
34
- self.reset_column_information
35
-
36
- # self.create config[:initial_data]
37
- self.replace_data(config[:initial_data])
38
- end
39
-
40
- def self.replace_data(data)
41
- # only select those attributes that were provided to us as columns. The rest is ignored.
42
- column_names = config[:columns].map{ |c| c[:name] }
43
- clean_data = data.collect{ |c| c.reject{ |k,v| !column_names.include?(k.to_s) } }
44
- self.delete_all
45
- self.create(clean_data)
46
- end
47
-
48
- private
49
-
50
- def self.refresh_token
51
- @@refresh_token ||= begin
52
- session = Netzke::Base.session
53
- config[:owner] + (session[:masq_user] || session[:masq_role] || session[:masq_world] || session[:netzke_user_id]).to_s
54
- end
55
- end
56
-
57
- end
@@ -1,44 +0,0 @@
1
- require File.dirname(__FILE__) + '/../spec_helper'
2
-
3
- describe Netzke::ActiveRecord::RelationExtensions do
4
- it "should accept different options in extend_with" do
5
- # Preparations
6
- 10.times do |i|
7
- Factory(:user, :first_name => "First Name #{i}", :role_id => i)
8
- end
9
-
10
- User.scope(:role_id_gt_7, User.where(["role_id > ?", 7]))
11
- User.scope(:role_id_gt, lambda{ |param| User.where(["role_id > ?", param]) })
12
-
13
- # Tests
14
- User.where({}).extend_with(["role_id >= ?", 5]).count.should == 5
15
-
16
- User.where({}).extend_with(:role_id_gt_7).count.should == 2
17
-
18
- User.where({}).extend_with(:role_id_gt, 2).count.should == 7
19
-
20
- User.where({}).extend_with([:role_id_gt, 3]).count.should == 6
21
-
22
- User.where({}).extend_with(:role_id => 5).first.first_name.should == "First Name 5"
23
-
24
- User.where(["role_id < ?", 7]).extend_with(lambda{ |relation| relation.where(["role_id > ?", 4]) }).count.should == 2
25
-
26
- # User.where({}).extend_with("select * from users where role_id > 6").all.size.should == 3
27
-
28
- end
29
-
30
- it "should be extendable with extend_with_netzke_conditions" do
31
- # Preparations
32
- roles = [Factory(:role, :name => "admin"), Factory(:role, :name => "user"), Factory(:role, :name => "superadmin")]
33
-
34
- # 3 users of each role
35
- 9.times do |i|
36
- Factory(:user, :role_id => roles[i%3].id)
37
- end
38
-
39
- # Tests
40
- User.where({}).extend_with_netzke_conditions(:role_id__eq => roles.last.id).count.should == 3
41
- User.where({}).extend_with_netzke_conditions(:role__name__eq => "admin").count.should == 3
42
- User.where({}).extend_with_netzke_conditions(:role__name__like => "%admin%").count.should == 6
43
- end
44
- end