netzke-core 0.2.1 → 0.2.2
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.
- data/CHANGELOG +6 -0
- data/Manifest +2 -0
- data/README.mdown +7 -6
- data/lib/app/models/netzke_layout.rb +16 -2
- data/lib/app/models/netzke_preference.rb +32 -13
- data/lib/netzke/base.rb +63 -30
- data/lib/netzke/controller_extensions.rb +6 -0
- data/lib/netzke/js_class_builder.rb +5 -3
- data/lib/netzke-core.rb +3 -7
- data/netzke-core.gemspec +4 -4
- data/test/app_root/db/migrate/20081222035855_create_netzke_preferences.rb +18 -0
- data/test/netzke_core_test.rb +35 -5
- data/test/netzke_preference_test.rb +36 -0
- metadata +5 -2
data/CHANGELOG
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
v0.2.2
|
2
|
+
js_ext_config instance method added for overwriting
|
3
|
+
Multiuser support
|
4
|
+
Using Rails.logger for logging
|
5
|
+
"config"-class method for every class inheriting Netzke::Base - for class-level configurations
|
6
|
+
|
1
7
|
v0.2.1
|
2
8
|
Fixed the path to ext-base-min.js for production mode.
|
3
9
|
Also works in Safari now.
|
data/Manifest
CHANGED
@@ -35,8 +35,10 @@ test/app_root/config/environments/postgresql.rb
|
|
35
35
|
test/app_root/config/environments/sqlite.rb
|
36
36
|
test/app_root/config/environments/sqlite3.rb
|
37
37
|
test/app_root/config/routes.rb
|
38
|
+
test/app_root/db/migrate/20081222035855_create_netzke_preferences.rb
|
38
39
|
test/app_root/script/console
|
39
40
|
test/core_ext_test.rb
|
40
41
|
test/netzke_core_test.rb
|
42
|
+
test/netzke_preference_test.rb
|
41
43
|
test/test_helper.rb
|
42
44
|
uninstall.rb
|
data/README.mdown
CHANGED
@@ -1,11 +1,12 @@
|
|
1
|
-
netzke-core
|
2
|
-
|
1
|
+
# netzke-core
|
2
|
+
Create Ext JS + Rails reusable components (widgets) with minimum effort.
|
3
3
|
|
4
|
-
|
4
|
+
Note that if you would like to modify this code or experiment with it, you may be better off cloning this project into your app's vendor/plugin directory - it will then behave as a Rails plugin.
|
5
5
|
|
6
|
-
Example
|
7
|
-
=======
|
6
|
+
# Example
|
8
7
|
|
9
8
|
See the tutorials on http://blog.writelesscode.com
|
10
9
|
|
11
|
-
|
10
|
+
Also see the netzke-basepack project.
|
11
|
+
|
12
|
+
Copyright (c) 2008-2009 Sergei Kozlov, released under the MIT license
|
@@ -1,8 +1,22 @@
|
|
1
1
|
class NetzkeLayout < ActiveRecord::Base
|
2
2
|
UNRELATED_ATTRS = %w(created_at updated_at position layout_id)
|
3
3
|
|
4
|
+
# Multi user support
|
5
|
+
def self.user
|
6
|
+
@@user ||= nil
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.user=(user)
|
10
|
+
@@user = user
|
11
|
+
end
|
12
|
+
|
4
13
|
def self.user_id
|
5
|
-
|
14
|
+
user && user.id
|
15
|
+
end
|
16
|
+
|
17
|
+
# normal create, but with a user_id merged-in
|
18
|
+
def self.create_with_user(config)
|
19
|
+
create(config.merge(:user_id => user_id))
|
6
20
|
end
|
7
21
|
|
8
22
|
def layout_items
|
@@ -10,7 +24,7 @@ class NetzkeLayout < ActiveRecord::Base
|
|
10
24
|
end
|
11
25
|
|
12
26
|
def self.by_widget(widget_name)
|
13
|
-
self.find(:first, :conditions => {:widget_name => widget_name, :user_id =>
|
27
|
+
self.find(:first, :conditions => {:widget_name => widget_name, :user_id => user_id})
|
14
28
|
end
|
15
29
|
|
16
30
|
def move_item(old_index, new_index)
|
@@ -1,12 +1,23 @@
|
|
1
|
+
# TODO: would be great to support somethnig like:
|
2
|
+
# NetzkePreference["name"].merge!({:a => 1, :b => 2}) # if NetzkePreference["name"] returns a hash
|
3
|
+
# or
|
4
|
+
# NetzkePreference["name"] << 2 # if NetzkePreference["name"] returns an array
|
5
|
+
# etc
|
6
|
+
#
|
1
7
|
class NetzkePreference < ActiveRecord::Base
|
2
|
-
|
3
|
-
|
8
|
+
ELEMENTARY_CONVERTION_METHODS= {'Fixnum' => 'to_i', 'String' => 'to_s', 'Float' => 'to_f', 'Symbol' => 'to_sym'}
|
9
|
+
|
10
|
+
# Multi user support
|
11
|
+
def self.user
|
12
|
+
@@user ||= nil
|
13
|
+
end
|
14
|
+
|
4
15
|
def self.user=(user)
|
5
16
|
@@user = user
|
6
17
|
end
|
7
18
|
|
8
|
-
def self.
|
9
|
-
|
19
|
+
def self.user_id
|
20
|
+
user && user.id
|
10
21
|
end
|
11
22
|
|
12
23
|
def self.widget_name=(value)
|
@@ -27,19 +38,21 @@ class NetzkePreference < ActiveRecord::Base
|
|
27
38
|
r = norm_value == 'false' ? false : (norm_value == 'true' || norm_value)
|
28
39
|
elsif klass == 'NilClass'
|
29
40
|
r = nil
|
30
|
-
elsif klass == 'Array'
|
41
|
+
elsif klass == 'Array' || klass == 'Hash'
|
31
42
|
r = JSON.parse(norm_value)
|
32
43
|
else
|
33
|
-
r = norm_value.send(
|
44
|
+
r = norm_value.send(ELEMENTARY_CONVERTION_METHODS[klass])
|
34
45
|
end
|
35
46
|
r
|
36
47
|
end
|
37
48
|
|
38
49
|
def normalized_value=(new_value)
|
39
50
|
# norm_value = (new_value.to_s if new_value == true or new_value == false) || new_value
|
40
|
-
case new_value.class.
|
51
|
+
case new_value.class.name
|
41
52
|
when "Array"
|
42
53
|
write_attribute(:value, new_value.to_json)
|
54
|
+
when "Hash"
|
55
|
+
write_attribute(:value, new_value.to_json)
|
43
56
|
else
|
44
57
|
write_attribute(:value, new_value.to_s)
|
45
58
|
end
|
@@ -48,7 +61,7 @@ class NetzkePreference < ActiveRecord::Base
|
|
48
61
|
|
49
62
|
def self.[](pref_name)
|
50
63
|
pref_name = pref_name.to_s
|
51
|
-
conditions = {:name => pref_name, :user_id =>
|
64
|
+
conditions = {:name => pref_name, :user_id => user_id, :widget_name => self.widget_name}
|
52
65
|
pref = self.find(:first, :conditions => conditions)
|
53
66
|
# pref = @@user.nil? ? self.find_by_name(pref_name) : self.find_by_name_and_user_id(pref_name, @@user.id)
|
54
67
|
pref && pref.normalized_value
|
@@ -56,11 +69,17 @@ class NetzkePreference < ActiveRecord::Base
|
|
56
69
|
|
57
70
|
def self.[]=(pref_name, new_value)
|
58
71
|
pref_name = pref_name.to_s
|
59
|
-
conditions = {:name => pref_name, :user_id =>
|
60
|
-
pref = self.find(:first, :conditions => conditions)
|
61
|
-
|
62
|
-
|
63
|
-
|
72
|
+
conditions = {:name => pref_name, :user_id => user_id, :widget_name => self.widget_name}
|
73
|
+
pref = self.find(:first, :conditions => conditions)
|
74
|
+
|
75
|
+
# if assigning nil, simply delete the eventually found preference
|
76
|
+
if new_value.nil?
|
77
|
+
pref && pref.destroy
|
78
|
+
else
|
79
|
+
pref ||= self.new(conditions)
|
80
|
+
pref.normalized_value = new_value
|
81
|
+
pref.save!
|
82
|
+
end
|
64
83
|
end
|
65
84
|
|
66
85
|
end
|
data/lib/netzke/base.rb
CHANGED
@@ -4,43 +4,41 @@ module Netzke
|
|
4
4
|
#
|
5
5
|
# Configuration:
|
6
6
|
# * Define NETZKE_BOOT_CONFIG in environment.rb to specify which Netzke functionality should be disabled
|
7
|
-
# to reduce the size of /netzke/netzke.[js|css]. Those Netzke gems that use additional JS-code
|
7
|
+
# to reduce the size of /netzke/netzke.[js|css]. Those Netzke gems that use additional JS/CSS-code
|
8
8
|
# should be aware of this constant.
|
9
9
|
#
|
10
10
|
class Base
|
11
|
-
# Helper class to read/write from/to widget's persistent preferences. TODO: rework it.
|
12
|
-
class Config
|
13
|
-
def initialize(widget_name)
|
14
|
-
@widget_name = widget_name
|
15
|
-
end
|
16
|
-
def []=(k,v)
|
17
|
-
NetzkePreference.widget_name = @widget_name
|
18
|
-
NetzkePreference[k] = v
|
19
|
-
end
|
20
|
-
def [](k)
|
21
|
-
NetzkePreference.widget_name = @widget_name
|
22
|
-
NetzkePreference[k]
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
11
|
# Client-side code (generates JS-class of the widget)
|
27
12
|
include Netzke::JsClassBuilder
|
28
13
|
|
29
|
-
|
30
|
-
|
31
|
-
# Global Netzke configuration
|
14
|
+
module ClassMethods
|
15
|
+
|
16
|
+
# Global Netzke::Base configuration
|
32
17
|
def config
|
33
|
-
|
34
|
-
# locations of javascript and css files (which will be automatically collected into one file and sent as /netzke/netzke.js and /netzke/netzke.css respectively)
|
18
|
+
set_default_config({
|
35
19
|
:javascripts => [],
|
36
|
-
:css => []
|
37
|
-
|
20
|
+
:css => [],
|
21
|
+
:layout_manager => "NetzkeLayout",
|
22
|
+
:persistent_config_manager => "NetzkePreference"
|
23
|
+
})
|
38
24
|
end
|
39
|
-
|
25
|
+
|
40
26
|
def short_widget_class_name
|
41
27
|
name.split("::").last
|
42
28
|
end
|
43
29
|
|
30
|
+
def user
|
31
|
+
@@user ||= nil
|
32
|
+
end
|
33
|
+
|
34
|
+
def user=(user)
|
35
|
+
@@user = user
|
36
|
+
|
37
|
+
# also set up the managers
|
38
|
+
persistent_config_manager_class && persistent_config_manager_class.user = user
|
39
|
+
layout_manager_class && layout_manager_class.user = user
|
40
|
+
end
|
41
|
+
|
44
42
|
#
|
45
43
|
# Use this class method to declare connection points between client side of a widget and its server side. A method in a widget class with the same name will be (magically) called by the client side of the widget. See Grid widget for an example
|
46
44
|
#
|
@@ -72,24 +70,58 @@ module Netzke
|
|
72
70
|
widget_class = "Netzke::#{config[:widget_class_name]}".constantize
|
73
71
|
widget_class.new(config)
|
74
72
|
end
|
73
|
+
|
74
|
+
def persistent_config_manager_class
|
75
|
+
config[:persistent_config_manager].constantize
|
76
|
+
rescue NameError
|
77
|
+
nil
|
78
|
+
end
|
79
|
+
|
80
|
+
def layout_manager_class
|
81
|
+
Netzke::Base.config[:layout_manager].constantize
|
82
|
+
rescue NameError
|
83
|
+
nil
|
84
|
+
end
|
85
|
+
|
86
|
+
private
|
87
|
+
def set_default_config(default_config)
|
88
|
+
@@config ||= {}
|
89
|
+
@@config[self.name] ||= default_config
|
90
|
+
@@config[self.name]
|
91
|
+
end
|
92
|
+
|
75
93
|
end
|
76
|
-
|
94
|
+
extend ClassMethods
|
95
|
+
|
77
96
|
attr_accessor :config, :server_confg, :parent, :logger, :id_name, :permissions
|
78
97
|
attr_reader :pref
|
79
98
|
|
80
99
|
def initialize(config = {}, parent = nil)
|
81
|
-
@logger = Logger.new("debug.log")
|
82
100
|
@config = initial_config.recursive_merge(config)
|
83
101
|
@parent = parent
|
84
102
|
@id_name = parent.nil? ? config[:name].to_s : "#{parent.id_name}__#{config[:name]}"
|
85
103
|
|
86
104
|
@flash = []
|
87
|
-
@pref = Config.new(@id_name)
|
88
105
|
|
89
106
|
@config[:ext_config] ||= {} # configuration used to instantiate JS class
|
90
|
-
|
107
|
+
|
91
108
|
process_permissions_config
|
92
109
|
end
|
110
|
+
|
111
|
+
# Rails' logger
|
112
|
+
def logger
|
113
|
+
Rails.logger
|
114
|
+
end
|
115
|
+
|
116
|
+
# Store some setting in the database as if it was a hash, e.g.:
|
117
|
+
# persistent_config["window.size"] = 100
|
118
|
+
# persistent_config["window.size"] => 100
|
119
|
+
# This method is current_user-aware
|
120
|
+
def persistent_config
|
121
|
+
config_klass = self.class.persistent_config_manager_class
|
122
|
+
config_klass && config_klass.widget_name = id_name # pass to the config class our unique name
|
123
|
+
config_klass || {} # if we don't have the presistent config manager, all the calls to it will always return nil, and the "="-operation will be ignored
|
124
|
+
end
|
93
125
|
|
94
126
|
def initial_config
|
95
127
|
{}
|
@@ -185,9 +217,10 @@ module Netzke
|
|
185
217
|
config[:allow] = [config[:allow]] if config[:allow].is_a?(Symbol) # so that config[:allow] => :write works
|
186
218
|
config[:allow] && config[:allow].each{|p| @permissions.merge!(p.to_sym => true)} # allow
|
187
219
|
|
188
|
-
# ... and then merge it with NetzkePreferences
|
220
|
+
# ... and then merge it with NetzkePreferences
|
189
221
|
available_permissions.each do |p|
|
190
|
-
|
222
|
+
persistent_permisson = persistent_config["permissions.#{p}"]
|
223
|
+
@permissions[p.to_sym] = persistent_permisson unless persistent_permisson.nil?
|
191
224
|
end
|
192
225
|
end
|
193
226
|
end
|
@@ -2,6 +2,12 @@ module Netzke
|
|
2
2
|
module ControllerExtensions
|
3
3
|
def self.included(base)
|
4
4
|
base.extend ControllerClassMethods
|
5
|
+
base.send(:before_filter, :set_user)
|
6
|
+
end
|
7
|
+
|
8
|
+
# pickup
|
9
|
+
def set_user
|
10
|
+
Netzke::Base.user = current_user if defined?(current_user)
|
5
11
|
end
|
6
12
|
|
7
13
|
def method_missing(method_name)
|
@@ -29,7 +29,7 @@ module Netzke
|
|
29
29
|
|
30
30
|
res.merge!(:widget_class_name => short_widget_class_name)
|
31
31
|
|
32
|
-
res.merge!(
|
32
|
+
res.merge!(js_ext_config)
|
33
33
|
res.merge!(:id => @id_name)
|
34
34
|
|
35
35
|
# include tools and actions
|
@@ -41,11 +41,13 @@ module Netzke
|
|
41
41
|
# include permissions
|
42
42
|
res.merge!(:permissions => permissions) unless available_permissions.empty?
|
43
43
|
|
44
|
-
# include eventual region_config
|
45
|
-
res.merge!(:region_config => config[:region_config])
|
46
44
|
res
|
47
45
|
end
|
48
46
|
|
47
|
+
def js_ext_config
|
48
|
+
config[:ext_config] || {}
|
49
|
+
end
|
50
|
+
|
49
51
|
# Generate instantiating - used when a widget is generated stand-alone (as a part of a HTML page)
|
50
52
|
def js_widget_instance
|
51
53
|
%Q(var #{config[:name].to_js} = new Ext.componentCache['#{short_widget_class_name}'](#{js_config.to_js});)
|
data/lib/netzke-core.rb
CHANGED
@@ -19,25 +19,21 @@ require 'vendor/facets/hash/recursive_merge'
|
|
19
19
|
end
|
20
20
|
|
21
21
|
if defined? ActionController
|
22
|
-
# Provide controllers with netzke class method
|
23
22
|
ActionController::Base.class_eval do
|
24
23
|
include Netzke::ControllerExtensions
|
25
24
|
end
|
26
25
|
|
27
|
-
# Include the route to
|
26
|
+
# Include the route to the Netzke controller
|
28
27
|
ActionController::Routing::RouteSet::Mapper.send :include, Netzke::Routing::MapperExtensions
|
29
28
|
end
|
30
29
|
|
31
30
|
if defined? ActionView
|
32
|
-
# Helpers to be put into layouts
|
33
31
|
ActionView::Base.send :include, Netzke::ActionViewExt
|
34
32
|
end
|
35
33
|
|
36
|
-
# Make this plugin auto-
|
34
|
+
# Make this plugin auto-reloadable for easier development
|
37
35
|
ActiveSupport::Dependencies.load_once_paths.delete(File.join(File.dirname(__FILE__)))
|
38
36
|
|
39
|
-
# Include
|
37
|
+
# Include javascript & styles
|
40
38
|
Netzke::Base.config[:javascripts] << "#{File.dirname(__FILE__)}/../javascripts/core.js"
|
41
|
-
|
42
|
-
# Include CSS
|
43
39
|
Netzke::Base.config[:css] << "#{File.dirname(__FILE__)}/../css/core.css"
|
data/netzke-core.gemspec
CHANGED
@@ -2,15 +2,15 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{netzke-core}
|
5
|
-
s.version = "0.2.
|
5
|
+
s.version = "0.2.2"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Sergei Kozlov"]
|
9
|
-
s.date = %q{2009-01-
|
9
|
+
s.date = %q{2009-01-23}
|
10
10
|
s.description = %q{Build ExtJS/Rails widgets with minimum effort}
|
11
11
|
s.email = %q{sergei@writelesscode.com}
|
12
12
|
s.extra_rdoc_files = ["CHANGELOG", "lib/app/controllers/netzke_controller.rb", "lib/app/models/netzke_layout.rb", "lib/app/models/netzke_preference.rb", "lib/netzke/action_view_ext.rb", "lib/netzke/base.rb", "lib/netzke/controller_extensions.rb", "lib/netzke/core_ext.rb", "lib/netzke/feedback_ghost.rb", "lib/netzke/js_class_builder.rb", "lib/netzke/routing.rb", "lib/netzke-core.rb", "lib/vendor/facets/hash/recursive_merge.rb", "LICENSE", "README.mdown", "tasks/netzke_core_tasks.rake"]
|
13
|
-
s.files = ["CHANGELOG", "css/core.css", "generators/netzke_core/netzke_core_generator.rb", "generators/netzke_core/templates/create_netzke_layouts.rb", "generators/netzke_core/templates/create_netzke_preferences.rb", "generators/netzke_core/USAGE", "init.rb", "install.rb", "javascripts/core.js", "lib/app/controllers/netzke_controller.rb", "lib/app/models/netzke_layout.rb", "lib/app/models/netzke_preference.rb", "lib/netzke/action_view_ext.rb", "lib/netzke/base.rb", "lib/netzke/controller_extensions.rb", "lib/netzke/core_ext.rb", "lib/netzke/feedback_ghost.rb", "lib/netzke/js_class_builder.rb", "lib/netzke/routing.rb", "lib/netzke-core.rb", "lib/vendor/facets/hash/recursive_merge.rb", "LICENSE", "Manifest", "netzke-core.gemspec", "Rakefile", "README.mdown", "tasks/netzke_core_tasks.rake", "test/app_root/app/controllers/application.rb", "test/app_root/config/boot.rb", "test/app_root/config/database.yml", "test/app_root/config/environment.rb", "test/app_root/config/environments/in_memory.rb", "test/app_root/config/environments/mysql.rb", "test/app_root/config/environments/postgresql.rb", "test/app_root/config/environments/sqlite.rb", "test/app_root/config/environments/sqlite3.rb", "test/app_root/config/routes.rb", "test/app_root/script/console", "test/core_ext_test.rb", "test/netzke_core_test.rb", "test/test_helper.rb", "uninstall.rb"]
|
13
|
+
s.files = ["CHANGELOG", "css/core.css", "generators/netzke_core/netzke_core_generator.rb", "generators/netzke_core/templates/create_netzke_layouts.rb", "generators/netzke_core/templates/create_netzke_preferences.rb", "generators/netzke_core/USAGE", "init.rb", "install.rb", "javascripts/core.js", "lib/app/controllers/netzke_controller.rb", "lib/app/models/netzke_layout.rb", "lib/app/models/netzke_preference.rb", "lib/netzke/action_view_ext.rb", "lib/netzke/base.rb", "lib/netzke/controller_extensions.rb", "lib/netzke/core_ext.rb", "lib/netzke/feedback_ghost.rb", "lib/netzke/js_class_builder.rb", "lib/netzke/routing.rb", "lib/netzke-core.rb", "lib/vendor/facets/hash/recursive_merge.rb", "LICENSE", "Manifest", "netzke-core.gemspec", "Rakefile", "README.mdown", "tasks/netzke_core_tasks.rake", "test/app_root/app/controllers/application.rb", "test/app_root/config/boot.rb", "test/app_root/config/database.yml", "test/app_root/config/environment.rb", "test/app_root/config/environments/in_memory.rb", "test/app_root/config/environments/mysql.rb", "test/app_root/config/environments/postgresql.rb", "test/app_root/config/environments/sqlite.rb", "test/app_root/config/environments/sqlite3.rb", "test/app_root/config/routes.rb", "test/app_root/db/migrate/20081222035855_create_netzke_preferences.rb", "test/app_root/script/console", "test/core_ext_test.rb", "test/netzke_core_test.rb", "test/netzke_preference_test.rb", "test/test_helper.rb", "uninstall.rb"]
|
14
14
|
s.has_rdoc = true
|
15
15
|
s.homepage = %q{http://writelesscode.com}
|
16
16
|
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Netzke-core", "--main", "README.mdown"]
|
@@ -18,7 +18,7 @@ Gem::Specification.new do |s|
|
|
18
18
|
s.rubyforge_project = %q{netzke-core}
|
19
19
|
s.rubygems_version = %q{1.3.1}
|
20
20
|
s.summary = %q{Build ExtJS/Rails widgets with minimum effort}
|
21
|
-
s.test_files = ["test/core_ext_test.rb", "test/netzke_core_test.rb"]
|
21
|
+
s.test_files = ["test/core_ext_test.rb", "test/netzke_core_test.rb", "test/netzke_preference_test.rb"]
|
22
22
|
|
23
23
|
if s.respond_to? :specification_version then
|
24
24
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class CreateNetzkePreferences < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :netzke_preferences do |t|
|
4
|
+
t.string :name
|
5
|
+
t.string :pref_type
|
6
|
+
t.string :value
|
7
|
+
t.integer :user_id
|
8
|
+
t.integer :role_id
|
9
|
+
t.string :widget_name
|
10
|
+
|
11
|
+
t.timestamps
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.down
|
16
|
+
drop_table :netzke_preferences
|
17
|
+
end
|
18
|
+
end
|
data/test/netzke_core_test.rb
CHANGED
@@ -40,15 +40,24 @@ module Netzke
|
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
|
+
# mocking the User class
|
44
|
+
class User
|
45
|
+
attr_accessor :id
|
46
|
+
def initialize(id)
|
47
|
+
@id = id
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
43
51
|
class NetzkeCoreTest < ActiveSupport::TestCase
|
44
52
|
include Netzke
|
45
53
|
|
46
54
|
def setup
|
47
|
-
object = mock()
|
48
|
-
object.stubs(:normalized_value)
|
49
|
-
object.stubs(:normalized_value=)
|
50
|
-
# object.stubs(:save!)
|
51
|
-
NetzkePreference.stubs(:find).returns(object)
|
55
|
+
# object = mock()
|
56
|
+
# object.stubs(:normalized_value)
|
57
|
+
# object.stubs(:normalized_value=)
|
58
|
+
# # object.stubs(:save!)
|
59
|
+
# NetzkePreference.stubs(:find).returns(object)
|
60
|
+
|
52
61
|
end
|
53
62
|
|
54
63
|
test "base class loaded" do
|
@@ -131,4 +140,25 @@ class NetzkeCoreTest < ActiveSupport::TestCase
|
|
131
140
|
assert(Widget, widget.class)
|
132
141
|
assert('a_widget', widget.config[:name])
|
133
142
|
end
|
143
|
+
|
144
|
+
test "class configuration" do
|
145
|
+
assert_equal(NetzkeLayout, Netzke::Base.layout_manager_class)
|
146
|
+
end
|
147
|
+
|
148
|
+
# test "multiuser" do
|
149
|
+
# Netzke::Base.current_user = User.new(1)
|
150
|
+
# Widget.new(:prohibit => :all, :name => 'widget')
|
151
|
+
#
|
152
|
+
# Netzke::Base.current_user = User.new(2)
|
153
|
+
# Widget.new(:prohibit => :read, :name => 'widget')
|
154
|
+
#
|
155
|
+
# Netzke::Base.current_user = User.new(1)
|
156
|
+
# widget = Widget.new(:name => 'widget')
|
157
|
+
# assert_equal({:read => false, :update => false}, widget.permissions)
|
158
|
+
#
|
159
|
+
# Netzke::Base.current_user = User.new(2)
|
160
|
+
# widget = Widget.new(:name => 'widget')
|
161
|
+
# assert_equal({:read => false, :update => true}, widget.permissions)
|
162
|
+
#
|
163
|
+
# end
|
134
164
|
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'netzke-core'
|
3
|
+
class NetzkePreferenceTest < ActiveSupport::TestCase
|
4
|
+
test "basic values" do
|
5
|
+
an_integer = 1976
|
6
|
+
a_float = 1976.1345
|
7
|
+
a_symbol = :a_symbol
|
8
|
+
a_true = true
|
9
|
+
a_false = false
|
10
|
+
a_nil = nil
|
11
|
+
a_hash = {"a" => an_integer, "b" => a_true, "c" => nil, "d" => a_float}
|
12
|
+
an_array = [1, "a", a_hash, [1,3,4], a_true, a_false, a_nil, a_float]
|
13
|
+
|
14
|
+
|
15
|
+
p = NetzkePreference
|
16
|
+
p[:a_hash] = a_hash
|
17
|
+
p["an_integer"] = an_integer
|
18
|
+
p[:a_true] = a_true
|
19
|
+
p[:a_false] = a_false
|
20
|
+
p[:a_nil] = a_nil
|
21
|
+
p[:an_array] = an_array
|
22
|
+
p[:a_symbol] = a_symbol
|
23
|
+
p[:a_float] = a_float
|
24
|
+
|
25
|
+
assert_equal(a_hash, p[:a_hash])
|
26
|
+
assert_equal(an_integer, p[:an_integer])
|
27
|
+
assert_equal(a_true, p[:a_true])
|
28
|
+
assert_equal(a_false, p[:a_false])
|
29
|
+
assert_equal(an_array, p[:an_array])
|
30
|
+
assert_equal(a_nil, p[:a_nil])
|
31
|
+
assert_equal(a_symbol, p[:a_symbol])
|
32
|
+
assert_equal(a_float, p[:a_float])
|
33
|
+
|
34
|
+
assert_equal(nil, p[:non_existing])
|
35
|
+
end
|
36
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: netzke-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sergei Kozlov
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-01-
|
12
|
+
date: 2009-01-23 00:00:00 -06:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -74,9 +74,11 @@ files:
|
|
74
74
|
- test/app_root/config/environments/sqlite.rb
|
75
75
|
- test/app_root/config/environments/sqlite3.rb
|
76
76
|
- test/app_root/config/routes.rb
|
77
|
+
- test/app_root/db/migrate/20081222035855_create_netzke_preferences.rb
|
77
78
|
- test/app_root/script/console
|
78
79
|
- test/core_ext_test.rb
|
79
80
|
- test/netzke_core_test.rb
|
81
|
+
- test/netzke_preference_test.rb
|
80
82
|
- test/test_helper.rb
|
81
83
|
- uninstall.rb
|
82
84
|
has_rdoc: true
|
@@ -113,3 +115,4 @@ summary: Build ExtJS/Rails widgets with minimum effort
|
|
113
115
|
test_files:
|
114
116
|
- test/core_ext_test.rb
|
115
117
|
- test/netzke_core_test.rb
|
118
|
+
- test/netzke_preference_test.rb
|