netzke-basepack 0.7.7 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (192) hide show
  1. data/.travis.yml +15 -10
  2. data/{CHANGELOG.rdoc → CHANGELOG.md} +146 -110
  3. data/LICENSE +7 -1
  4. data/README.md +47 -56
  5. data/Rakefile +5 -5
  6. data/config/before-travis.sh +10 -0
  7. data/javascripts/basepack.js +0 -130
  8. data/javascripts/netzkeremotecombo.js +59 -0
  9. data/lib/netzke/basepack.rb +9 -14
  10. data/lib/netzke/basepack/accordion.rb +45 -0
  11. data/lib/netzke/basepack/active_record.rb +12 -0
  12. data/lib/netzke/basepack/active_record/relation_extensions.rb +27 -0
  13. data/lib/netzke/basepack/columns.rb +309 -0
  14. data/lib/netzke/basepack/data_accessor.rb +22 -12
  15. data/lib/netzke/basepack/data_adapters/abstract_adapter.rb +75 -11
  16. data/lib/netzke/basepack/data_adapters/active_record_adapter.rb +154 -49
  17. data/lib/netzke/basepack/fields.rb +162 -0
  18. data/lib/netzke/basepack/form.rb +136 -0
  19. data/lib/netzke/basepack/{form_panel → form}/javascripts/comma_list_cbg.js +0 -1
  20. data/lib/netzke/basepack/{form_panel/javascripts/form_panel.js → form/javascripts/form.js} +20 -26
  21. data/lib/netzke/basepack/{form_panel → form}/javascripts/n_radio_group.js +0 -1
  22. data/lib/netzke/basepack/{form_panel → form}/javascripts/readonly_mode.js +0 -0
  23. data/lib/netzke/basepack/form/services.rb +115 -0
  24. data/lib/netzke/basepack/{form_panel → form}/stylesheets/readonly_mode.css +0 -0
  25. data/lib/netzke/basepack/grid.rb +355 -0
  26. data/lib/netzke/basepack/{grid_panel → grid}/javascripts/advanced_search.js +1 -1
  27. data/lib/netzke/basepack/{grid_panel → grid}/javascripts/check_column_fix.js +0 -0
  28. data/lib/netzke/basepack/{grid_panel → grid}/javascripts/edit_in_form.js +3 -3
  29. data/lib/netzke/basepack/{grid_panel → grid}/javascripts/event_handling.js +5 -2
  30. data/lib/netzke/basepack/{grid_panel/javascripts/grid_panel.js → grid/javascripts/grid.js} +120 -132
  31. data/lib/netzke/basepack/{grid_panel → grid}/javascripts/misc.js +0 -0
  32. data/lib/netzke/basepack/grid/services.rb +216 -0
  33. data/lib/netzke/basepack/item_persistence.rb +44 -0
  34. data/lib/netzke/basepack/item_persistence/events_plugin.rb +47 -0
  35. data/lib/netzke/basepack/{paging_form_panel.rb → paging_form.rb} +24 -30
  36. data/lib/netzke/basepack/{paging_form_panel/javascripts/paging_form_panel.js → paging_form/javascripts/paging_form.js} +2 -4
  37. data/lib/netzke/basepack/query_builder.rb +44 -73
  38. data/lib/netzke/basepack/query_builder/javascripts/query_builder.js +16 -2
  39. data/lib/netzke/basepack/record_form_window.rb +67 -0
  40. data/lib/netzke/basepack/search_panel.rb +22 -24
  41. data/lib/netzke/basepack/search_panel/javascripts/condition_field.js +2 -2
  42. data/lib/netzke/basepack/search_window.rb +47 -53
  43. data/lib/netzke/basepack/simple_app.rb +10 -13
  44. data/lib/netzke/basepack/simple_app/javascripts/simple_app.js +2 -8
  45. data/lib/netzke/basepack/tab_panel.rb +5 -4
  46. data/lib/netzke/basepack/tab_panel/javascripts/tab_panel.js +5 -5
  47. data/lib/netzke/basepack/version.rb +2 -2
  48. data/lib/netzke/basepack/viewport.rb +16 -0
  49. data/lib/netzke/basepack/window.rb +27 -18
  50. data/lib/netzke/basepack/window/javascripts/window.js +7 -1
  51. data/lib/netzke/basepack/wrap_lazy_loaded.rb +18 -18
  52. data/locales/en.yml +40 -24
  53. data/netzke-basepack.gemspec +51 -82
  54. data/stylesheets/basepack.css +0 -41
  55. data/test/basepack_test_app/Gemfile +9 -46
  56. data/test/basepack_test_app/Gemfile.lock +61 -96
  57. data/test/basepack_test_app/app/components/author_form.rb +8 -5
  58. data/test/basepack_test_app/app/components/author_grid.rb +2 -2
  59. data/test/basepack_test_app/app/components/book_form.rb +34 -31
  60. data/test/basepack_test_app/app/components/book_form_with_defaults.rb +6 -7
  61. data/test/basepack_test_app/app/components/book_form_with_file_upload.rb +10 -0
  62. data/test/basepack_test_app/app/components/book_form_with_nested_attributes.rb +5 -6
  63. data/test/basepack_test_app/app/components/book_grid.rb +19 -8
  64. data/test/basepack_test_app/app/components/book_grid_filtering.rb +4 -7
  65. data/test/basepack_test_app/app/components/book_grid_loader.rb +28 -15
  66. data/test/basepack_test_app/app/components/book_grid_with_custom_columns.rb +45 -21
  67. data/test/basepack_test_app/app/components/book_grid_with_default_values.rb +26 -8
  68. data/test/basepack_test_app/app/components/book_grid_with_excluded_columns.rb +11 -0
  69. data/test/basepack_test_app/app/components/book_grid_with_extra_feedback.rb +2 -2
  70. data/test/basepack_test_app/app/components/book_grid_with_extra_filters.rb +7 -6
  71. data/test/basepack_test_app/app/components/book_grid_with_mass_assignment_security.rb +9 -0
  72. data/test/basepack_test_app/app/components/book_grid_with_nested_attributes.rb +9 -9
  73. data/test/basepack_test_app/app/components/book_grid_with_overridden_columns.rb +5 -3
  74. data/test/basepack_test_app/app/components/book_grid_with_paging.rb +6 -8
  75. data/test/basepack_test_app/app/components/book_grid_with_persistence.rb +6 -4
  76. data/test/basepack_test_app/app/components/book_grid_with_scope.rb +6 -0
  77. data/test/basepack_test_app/app/components/book_grid_with_scoped_authors.rb +10 -7
  78. data/test/basepack_test_app/app/components/book_grid_with_virtual_attributes.rb +21 -13
  79. data/test/basepack_test_app/app/components/book_paging_form.rb +21 -0
  80. data/test/basepack_test_app/app/components/book_query_builder.rb +7 -6
  81. data/test/basepack_test_app/app/components/book_with_custom_primary_key_grid.rb +6 -7
  82. data/test/basepack_test_app/app/components/books_bound_to_author.rb +9 -7
  83. data/test/basepack_test_app/app/components/border_layout_panel_with_persistence.rb +12 -0
  84. data/test/basepack_test_app/app/components/double_book_grid.rb +19 -14
  85. data/test/basepack_test_app/app/components/form_without_model.rb +15 -16
  86. data/test/basepack_test_app/app/components/grid_with_initial_sorting.rb +7 -0
  87. data/test/basepack_test_app/app/components/grid_with_inline_data.rb +7 -0
  88. data/test/basepack_test_app/app/components/paging_form_with_search.rb +2 -2
  89. data/test/basepack_test_app/app/components/panel_with_persistent_regions.rb +35 -0
  90. data/test/basepack_test_app/app/components/query_builder.rb +7 -0
  91. data/test/basepack_test_app/app/components/simple_panel.rb +16 -11
  92. data/test/basepack_test_app/app/components/simple_window.rb +7 -6
  93. data/test/basepack_test_app/app/components/some_accordion.rb +18 -0
  94. data/test/basepack_test_app/app/components/some_auth_app.rb +5 -5
  95. data/test/basepack_test_app/app/components/some_border_layout.rb +20 -20
  96. data/test/basepack_test_app/app/components/some_search_panel.rb +6 -0
  97. data/test/basepack_test_app/app/components/some_simple_app.rb +30 -16
  98. data/test/basepack_test_app/app/components/some_tab_panel.rb +18 -15
  99. data/test/basepack_test_app/app/components/user_form.rb +18 -16
  100. data/test/basepack_test_app/app/components/user_form_with_default_fields.rb +5 -6
  101. data/test/basepack_test_app/app/components/user_grid.rb +11 -6
  102. data/test/basepack_test_app/app/components/user_grid_with_customized_form_fields.rb +5 -3
  103. data/test/basepack_test_app/app/components/window_component_loader.rb +25 -21
  104. data/test/basepack_test_app/app/models/address.rb +0 -26
  105. data/test/basepack_test_app/app/models/author.rb +0 -31
  106. data/test/basepack_test_app/app/models/book.rb +1 -42
  107. data/test/basepack_test_app/app/models/book_with_custom_primary_key.rb +1 -23
  108. data/test/basepack_test_app/app/models/role.rb +0 -21
  109. data/test/basepack_test_app/app/models/user.rb +0 -24
  110. data/test/basepack_test_app/app/views/layouts/components.html.erb +1 -1
  111. data/test/basepack_test_app/config/application.rb +1 -1
  112. data/test/basepack_test_app/config/database.yml.travis +2 -6
  113. data/test/basepack_test_app/config/initializers/netzke.rb +1 -6
  114. data/test/basepack_test_app/db/schema.rb +14 -14
  115. data/test/basepack_test_app/features/accordion_panel.feature +2 -2
  116. data/test/basepack_test_app/features/form_panel.feature +7 -7
  117. data/test/basepack_test_app/features/grid_panel.feature +93 -39
  118. data/test/basepack_test_app/features/grid_panel_with_custom_primary_key.feature +2 -1
  119. data/test/basepack_test_app/features/grid_sorting.feature +30 -6
  120. data/test/basepack_test_app/features/paging_form_panel.feature +7 -7
  121. data/test/basepack_test_app/features/persistent_regions.feature +30 -0
  122. data/test/basepack_test_app/features/search_in_grid.feature +5 -5
  123. data/test/basepack_test_app/features/simple_app.feature +6 -7
  124. data/test/basepack_test_app/features/step_definitions/form_panel_steps.rb +1 -1
  125. data/test/basepack_test_app/features/step_definitions/generic_steps.rb +109 -4
  126. data/test/basepack_test_app/features/step_definitions/grid_panel_steps.rb +8 -10
  127. data/test/basepack_test_app/features/step_definitions/window_steps.rb +27 -0
  128. data/test/basepack_test_app/features/tab_panel.feature +1 -1
  129. data/test/basepack_test_app/features/window.feature +17 -0
  130. data/test/unit/accordion_panel_test.rb +2 -2
  131. data/test/unit/grid_panel_test.rb +4 -4
  132. metadata +57 -83
  133. data/TODO.rdoc +0 -8
  134. data/lib/generators/netzke/basepack_generator.rb +0 -10
  135. data/lib/generators/netzke/templates/assets/ts-checkbox.gif +0 -0
  136. data/lib/generators/netzke/templates/create_netzke_field_lists.rb +0 -18
  137. data/lib/netzke/active_record.rb +0 -20
  138. data/lib/netzke/active_record/attributes.rb +0 -259
  139. data/lib/netzke/active_record/combobox_options.rb +0 -16
  140. data/lib/netzke/active_record/relation_extensions.rb +0 -37
  141. data/lib/netzke/basepack/accordion_panel.rb +0 -39
  142. data/lib/netzke/basepack/action_column.rb +0 -68
  143. data/lib/netzke/basepack/action_column/javascripts/action_column.js +0 -61
  144. data/lib/netzke/basepack/auth_app.rb +0 -159
  145. data/lib/netzke/basepack/basic_app.rb +0 -7
  146. data/lib/netzke/basepack/border_layout_panel.rb +0 -53
  147. data/lib/netzke/basepack/border_layout_panel/javascripts/border_layout_panel.js +0 -40
  148. data/lib/netzke/basepack/data_adapters/data_mapper_adapter.rb +0 -264
  149. data/lib/netzke/basepack/data_adapters/sequel_adapter.rb +0 -260
  150. data/lib/netzke/basepack/form_panel.rb +0 -144
  151. data/lib/netzke/basepack/form_panel/fields.rb +0 -208
  152. data/lib/netzke/basepack/form_panel/javascripts/misc.js +0 -4
  153. data/lib/netzke/basepack/form_panel/services.rb +0 -142
  154. data/lib/netzke/basepack/grid_panel.rb +0 -441
  155. data/lib/netzke/basepack/grid_panel/columns.rb +0 -400
  156. data/lib/netzke/basepack/grid_panel/javascripts/rows-dd.js +0 -281
  157. data/lib/netzke/basepack/grid_panel/record_form_window.rb +0 -41
  158. data/lib/netzke/basepack/grid_panel/services.rb +0 -235
  159. data/lib/netzke/basepack/panel.rb +0 -11
  160. data/lib/netzke/basepack/wrapper.rb +0 -28
  161. data/lib/netzke/data_mapper.rb +0 -18
  162. data/lib/netzke/data_mapper/attributes.rb +0 -273
  163. data/lib/netzke/data_mapper/combobox_options.rb +0 -11
  164. data/lib/netzke/data_mapper/relation_extensions.rb +0 -38
  165. data/lib/netzke/sequel.rb +0 -18
  166. data/lib/netzke/sequel/attributes.rb +0 -274
  167. data/lib/netzke/sequel/combobox_options.rb +0 -10
  168. data/lib/netzke/sequel/relation_extensions.rb +0 -40
  169. data/locales/zh-cn.yml +0 -79
  170. data/test/basepack_test_app/app/components/book_form_with_custom_fields.rb +0 -21
  171. data/test/basepack_test_app/app/components/book_grid_with_column_actions.rb +0 -15
  172. data/test/basepack_test_app/app/components/book_grid_with_defaults.rb +0 -6
  173. data/test/basepack_test_app/app/components/book_paging_form_panel.rb +0 -22
  174. data/test/basepack_test_app/app/components/generic_user_form.rb +0 -12
  175. data/test/basepack_test_app/app/components/simple_accordion.rb +0 -11
  176. data/test/basepack_test_app/app/components/simple_tab_panel.rb +0 -11
  177. data/test/basepack_test_app/app/components/simple_wrapper.rb +0 -7
  178. data/test/basepack_test_app/app/components/some_accordion_panel.rb +0 -22
  179. data/test/basepack_test_app/app/presenters/forms/generic_user.rb +0 -6
  180. data/test/basepack_test_app/app/views/components/loadable_window.html.erb +0 -9
  181. data/test/basepack_test_app/app/views/components/simple_panel.html.erb +0 -1
  182. data/test/basepack_test_app/features/components_in_view.feature +0 -11
  183. data/test/basepack_test_app/features/simple_panel.feature +0 -11
  184. data/test/basepack_test_app/features/validations_in_grid.feature +0 -13
  185. data/test/basepack_test_app/features/virtual_attributes.feature +0 -16
  186. data/test/basepack_test_app/spec/components/form_panel_spec.rb +0 -53
  187. data/test/basepack_test_app/spec/components/grid_panel_spec.rb +0 -10
  188. data/test/basepack_test_app/spec/data_adapter/adapter_spec.rb +0 -68
  189. data/test/basepack_test_app/spec/data_adapter/attributes_spec.rb +0 -56
  190. data/test/basepack_test_app/spec/data_adapter/relation_extensions_spec.rb +0 -125
  191. data/test/basepack_test_app/spec/factories.rb +0 -28
  192. data/test/basepack_test_app/spec/spec_helper.rb +0 -39
@@ -1,21 +0,0 @@
1
- class BookFormWithCustomFields < Netzke::Basepack::FormPanel
2
- js_property :title, Book.model_name.human
3
-
4
- def default_config
5
- super.merge(
6
- :model => "Book",
7
- :record => Book.first,
8
- # :mode => :lockable,
9
- :items => [
10
- :title,
11
- {:name => :notes, :read_only => true},
12
- :author__first_name,
13
- :author__last_name,
14
- :digitized,
15
- :exemplars,
16
- :last_read_at
17
- ]
18
- )
19
- end
20
-
21
- end
@@ -1,15 +0,0 @@
1
- # Implements a column action :delete_row
2
- class BookGridWithColumnActions < Netzke::Basepack::GridPanel
3
- include Netzke::Basepack::ActionColumn
4
-
5
- model "Book"
6
-
7
- column_action :delete_row, :icon => "#{Netzke::Core.ext_uri}/resources/themes/images/default/tree/drop-no.gif"
8
-
9
- js_method :on_delete_row, <<-JS
10
- function(record){
11
- this.getSelectionModel().select(record);
12
- this.onDel();
13
- }
14
- JS
15
- end
@@ -1,6 +0,0 @@
1
- # Not used in automatic tests
2
- class BookGridWithDefaults < Netzke::Basepack::GridPanel
3
- def default_config
4
- super.merge(model: 'Book')
5
- end
6
- end
@@ -1,22 +0,0 @@
1
- class BookPagingFormPanel < Netzke::Basepack::PagingFormPanel
2
- def default_config
3
- super.merge({
4
- :title => "Digitized books",
5
- :model => "Book",
6
- :record => Book.first,
7
- # :scope => {:digitized => true},
8
- :mode => :lockable,
9
- :items => [{:layout => :hbox, :label_align => :top, :border => false, :defaults => {:border => false}, :items => [{
10
- :flex => 2,
11
- :layout => :anchor,
12
- :defaults => {:anchor => "-8"},
13
- :items => [:title, :notes, :digitized, :created_at, :updated_at, :last_read_at]
14
- },{
15
- :flex => 1,
16
- :layout => :anchor,
17
- :defaults => {:anchor => "-8"},
18
- :items => [:author__name, {:name => :author__first_name, :read_only => true}, :exemplars, :published_on]
19
- }]}]
20
- })
21
- end
22
- end
@@ -1,12 +0,0 @@
1
- class GenericUserForm < Netzke::Basepack::FormPanel
2
-
3
- config do
4
- {
5
- :model => 'User',
6
- :title => 'Users',
7
- :record_id => User.first.id,
8
- :items => [:id, :first_name]
9
- }
10
- end
11
-
12
- end
@@ -1,11 +0,0 @@
1
- class SimpleAccordion < Netzke::Basepack::AccordionPanel
2
- config :items => [{
3
- :html => "I'm a simple Ext.Panel",
4
- :title => "Panel One"
5
- },{
6
- :class_name => "SimplePanel",
7
- :update_text => "Update for Panel Two",
8
- :title => "Panel Two",
9
- :lazy_loading => true
10
- }]
11
- end
@@ -1,11 +0,0 @@
1
- class SimpleTabPanel < Netzke::Basepack::TabPanel
2
- config :items => [{
3
- :html => "I'm a simple Ext.Panel",
4
- :title => "Panel One"
5
- },{
6
- :class_name => "SimplePanel",
7
- :update_text => "Update for Panel Two",
8
- :title => "Panel Two",
9
- :lazy_loading => true
10
- }]
11
- end
@@ -1,7 +0,0 @@
1
- class SimpleWrapper < Netzke::Basepack::Wrapper
2
- def config
3
- {
4
- :items => [{:class_name => "Basepack::Panel", :html => "A Panel wrapped into the (invisible) wrapper", :title => "Wrapped Panel"}]
5
- }
6
- end
7
- end
@@ -1,22 +0,0 @@
1
- class SomeAccordionPanel < Netzke::Basepack::AccordionPanel
2
- def configuration
3
- super.merge(
4
- :layout_config => {
5
- :animate => true,
6
- },
7
- :items => [:panel_one.component, :panel_two.component]
8
- )
9
- end
10
-
11
- component :panel_one, {
12
- :class_name => "Basepack::Panel",
13
- :title => "Panel One"
14
- }
15
-
16
- component :panel_two, {
17
- :class_name => "Basepack::Panel",
18
- :title => "Panel Two",
19
- :html => "Some html",
20
- :lazy_loading => true
21
- }
22
- end
@@ -1,6 +0,0 @@
1
- module Forms
2
- class GenericUser < User
3
- netzke_attribute :first_name, :xtype => "combo", :store => ["Paul", "Max"]
4
- netzke_expose_attributes :id, :first_name, :last_name
5
- end
6
- end
@@ -1,9 +0,0 @@
1
- <input type="button" value="Show window" onClick="Netzke.page.windowOne.show(); Ext.get(this).hide();" />
2
-
3
- <%= netzke :window_one,
4
- :class_name => "Netzke::Basepack::Window",
5
- :title => "Wow",
6
- :y => 10,
7
- :width => 500, :height => 400,
8
- :persistence => true
9
- %>
@@ -1 +0,0 @@
1
- <%= netzke :simple_panel, :html => "Simple Panel content" %>
@@ -1,11 +0,0 @@
1
- Feature: Components in view
2
- In order to value
3
- As a role
4
- I want feature
5
-
6
- @javascript
7
- Scenario: Components configured in the view should render properly
8
- When I go to the "simple panel" view
9
- Then I should see "Simple Panel content"
10
- When I press "Update html"
11
- Then I should see "HTML received from server"
@@ -1,11 +0,0 @@
1
- Feature: Panel
2
- In order to value
3
- As a role
4
- I want feature
5
-
6
- @selenium
7
- Scenario: The SimplePanel component should be able to update its body's HTML from the server
8
- When I go to the SimplePanel test page
9
- Then I should see "Original HTML"
10
- When I press "Update html"
11
- Then I should see "HTML received from server"
@@ -1,13 +0,0 @@
1
- Feature: Validations in grid
2
- In order to value
3
- As a role
4
- I want feature
5
-
6
- # @javascript
7
- # Scenario: Multi-editing in grid with some records invalid
8
- # Given an author exists with first_name: "Vladimir", last_name: "Nabokov"
9
- # And a book exists with title: "Lolita", author: that author
10
- # And an author exists with first_name: "Carlos", last_name: "Castaneda"
11
- # And a book exists with title: "Luzhin Defence", author: that author
12
- # When I go to the BookGridWithCustomColumns test page
13
- #
@@ -1,16 +0,0 @@
1
- Feature: Window component loader
2
- In order to value
3
- As a role
4
- I want feature
5
-
6
- @javascript
7
- Scenario: Creating an author on the fly with BookGridWithVirtualAttributes
8
- Given an author exists with first_name: "Victor"
9
- And a book exists with author: that author, title: "Lolita"
10
- And I am on the BookGridWithVirtualAttributes test page
11
- Then I should see "Victor"
12
-
13
- When I edit row 1 of the grid with author__first_name: "Vladimir"
14
- And I press "Apply"
15
- And I wait for the response from the server
16
- Then I should see "Vladimir"
@@ -1,53 +0,0 @@
1
- require File.dirname(__FILE__) + '/../spec_helper'
2
-
3
- describe Netzke::Basepack::FormPanel do
4
- it "should have correct fields" do
5
- form = Netzke::Basepack::FormPanel.new(:model => 'User')
6
- form.fields_from_model.keys.map(&:to_s).sort.should == %w(created_at first_name id last_name role__name updated_at)
7
- end
8
-
9
- it "should extract fields from config" do
10
- form = Netzke::Basepack::FormPanel.new(:model => 'User', :items => [{:xtype => 'fieldset', :items => [:first_name, {:name => "last_name"}]}, :created_at, {:name => :updated_at}])
11
-
12
- form.fields_from_config.keys.map(&:to_s).sort.should == %w(created_at first_name id last_name updated_at)
13
- end
14
-
15
- it "should set correct xtype for columns" do
16
- form = Netzke::Basepack::FormPanel.new(:model => 'User', :items => [:first_name, :created_at, :role__name])
17
-
18
- form.fields[:first_name][:xtype].should == :textfield
19
- form.fields[:created_at][:xtype].should == :xdatetime
20
- form.fields[:role__name][:xtype].should == :netzkeremotecombo
21
- end
22
-
23
- it "should set correct default field labels" do
24
- form = Netzke::Basepack::FormPanel.new(:model => 'User', :items => [:first_name, :created_at, :role__name])
25
-
26
- form.fields[:first_name][:field_label].should == "First name"
27
- form.fields[:created_at][:field_label].should == "Created at"
28
- form.fields[:role__name][:field_label].should == "Role name"
29
- end
30
-
31
- it "should add primary key field automatically when omitted" do
32
- form = Netzke::Basepack::FormPanel.new(:model => 'User', :items => [:first_name, :last_name, :role__name])
33
- form.fields[:id].should_not be_nil
34
- end
35
-
36
- it "should pass normalized items to JS" do
37
- form = Netzke::Basepack::FormPanel.new(:model => 'User', :items => [
38
- {:xtype => 'fieldset', :items => [
39
- :first_name,
40
- {:name => "last_name"}
41
- ]},
42
- :created_at,
43
- {:name => :updated_at}
44
- ])
45
-
46
- form.items[0][:name].should == "id"
47
- form.items[1][:items][0][:name].should == "first_name"
48
- form.items[1][:items][1][:name].should == "last_name"
49
- form.items[2][:name].should == "created_at"
50
- form.items[3][:name].should == "updated_at"
51
- end
52
-
53
- end
@@ -1,10 +0,0 @@
1
- require File.dirname(__FILE__) + '/../spec_helper'
2
-
3
- describe Netzke::Basepack::GridPanel do
4
- it "should have correct amount of default columns" do
5
- u1 = Factory(:user)
6
- grid = Netzke::Basepack::GridPanel.new(:model => 'User')
7
-
8
- grid.columns.size.should == 6
9
- end
10
- end
@@ -1,68 +0,0 @@
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
@@ -1,56 +0,0 @@
1
- require File.dirname(__FILE__) + '/../spec_helper'
2
-
3
- describe Netzke::ActiveRecord::Attributes do
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)
6
- end
7
-
8
- it "should return exposed Netzke attributes" do
9
- class UserExt < User
10
- netzke_expose_attributes :first_name, :created_at
11
- end
12
- UserExt.netzke_attributes.map{ |a| a[:name] }.should =~ %w(id first_name created_at)
13
- end
14
-
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 last_read_at published_on)
17
- Book.netzke_attributes.detect{ |a| a[:name] == "author__name" }[:attr_type].should == :string
18
- end
19
-
20
- it "should be possible to access author's id via a book using association attribute" do
21
- author = Factory(:author)
22
- book = Factory(:book, :author => author)
23
- book.value_for_attribute({:name => :author__first_name}).should == author.id
24
- end
25
-
26
- it "should be possible to assign author's name via a book using association attribute" do
27
- author = Factory(:author)
28
- book = Factory(:book, :author => author)
29
- book.set_value_for_attribute({:name => :author__first_name, :nested_attribute => true}, "Carlitos")
30
- author.reload if defined? Sequel::Model
31
- author.first_name.should == "Carlitos"
32
- end
33
-
34
- it "should be possible to change author for a book using association attribute" do
35
- author_carlos = Factory(:author, :first_name => "Carlos")
36
- author_herman = Factory(:author, :first_name => "Herman")
37
- book = Factory(:book, :author => author_carlos)
38
- book.set_value_for_attribute({:name => :author__first_name}, author_herman.id)
39
- book.author_id.should == author_herman.id
40
- end
41
-
42
- it "should be possible to change address of a user (has_one association) via association attribute without specifying :nested_attribute => true" do
43
- address = Factory(:address)
44
- user = Factory(:user)
45
- user.address = address
46
- user.set_value_for_attribute({:name => :address__city}, "Hidden Treasures")
47
- address.city.should == "Hidden Treasures"
48
- end
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
-
56
- end
@@ -1,125 +0,0 @@
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
-