padrino-admin 0.2.9 → 0.4.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.
@@ -0,0 +1,98 @@
1
+ require 'helper'
2
+
3
+ class TestAccessControl < Test::Unit::TestCase
4
+
5
+ def setup
6
+ load_fixture 'data_mapper'
7
+ @access = Class.new(Padrino::AccessControl::Base)
8
+
9
+ @access.roles_for :any do |role|
10
+ role.allow "/sessions"
11
+ role.deny "/special"
12
+ end
13
+
14
+ @access.roles_for :admin do |role, account|
15
+ role.allow "/admin/base"
16
+ role.deny "/admin/accounts/details"
17
+ role.deny "/admin/accounts/details" # Only for check that we don't have two paths equal
18
+
19
+ role.project_module "Padrino's Dashboard" do |project|
20
+ project.menu :general_settings, "/admin/settings" do |submenu|
21
+ submenu.add :accounts, "/admin/accounts" do |submenu|
22
+ submenu.add :sub_accounts, "/admin/accounts/subaccounts"
23
+ submenu.add :sub_accounts, "/admin/accounts/subaccounts" # Only for check that we don't have two paths equal
24
+ end
25
+ end
26
+ end
27
+ end
28
+
29
+ @access.roles_for :editor, :admin do |role, account|
30
+ role.project_module :categories do |project|
31
+ account.categories.each do |category|
32
+ project.menu category.name, "/admin/categories/#{category.id}.js"
33
+ end
34
+ end
35
+ end
36
+ end
37
+
38
+ context 'for authorization functionality' do
39
+
40
+ should 'check empty auths' do
41
+ empty = Class.new(Padrino::AccessControl::Base)
42
+ assert empty.auths.can?("/foo/bar")
43
+ assert ! empty.auths.cannot?("/foo/bar")
44
+ end
45
+
46
+ should 'check auths without account' do
47
+ assert_equal ["/sessions"], @access.auths.allowed
48
+ assert_equal ["/special"], @access.auths.denied
49
+ end
50
+
51
+ should 'act as can can' do
52
+ assert @access.auths.can?("/sessions")
53
+ assert @access.auths.cannot?("/special")
54
+ assert ! @access.auths.can?("/special")
55
+ end
56
+
57
+ should 'check auths for an editor' do
58
+ assert_equal ["/special"], @access.auths(Account.editor).denied
59
+ assert_equal ["/sessions"] +
60
+ Account.editor.categories.collect { |c| "/admin/categories/#{c.id}.js" }.uniq,
61
+ @access.auths(Account.editor).allowed
62
+ end
63
+
64
+ should 'allow and deny paths for admin' do
65
+ allowed = ["/sessions", "/admin/base", "/admin/settings", "/admin/accounts", "/admin/accounts/subaccounts"] +
66
+ Account.admin.categories.collect { |c| "/admin/categories/#{c.id}.js" }.uniq
67
+ assert_equal ["/special", "/admin/accounts/details"], @access.auths(Account.admin).denied
68
+ assert_equal allowed, @access.auths(Account.admin).allowed
69
+ end
70
+
71
+ should 'allow and deny paths for editor' do
72
+ assert_equal ["/special"], @access.auths(Account.editor).denied
73
+ assert_equal ["/sessions"] + Account.editor.categories.collect { |c| "/admin/categories/#{c.id}.js" }.uniq, @access.auths(Account.editor).allowed
74
+ end
75
+ end
76
+
77
+ context 'for project modules functionality do' do
78
+
79
+ should 'have empty modules if no account given' do
80
+ assert_equal [], @access.auths.project_modules
81
+ end
82
+
83
+ should 'check modules uids' do
84
+ assert_equal [:padrinosdashboard, :categories], @access.auths(Account.admin).project_modules.collect(&:uid)
85
+ assert_equal [:categories], @access.auths(Account.editor).project_modules.collect(&:uid)
86
+ end
87
+
88
+ should 'check a module config' do
89
+ menu = Account.editor.categories.collect { |c| { :text => c.name, :handler => "function(){ Admin.app.load('/admin/categories/#{c.id}.js') }" } }
90
+ assert_equal [{ :text => "Categories", :menu => menu }], @access.auths(Account.editor).project_modules.collect(&:config)
91
+ end
92
+
93
+ should 'check config handlers' do
94
+ assert_kind_of Padrino::ExtJs::Variable, @access.auths(Account.editor).project_modules.collect(&:config).first[:menu].first[:handler]
95
+ end
96
+ end
97
+
98
+ end
@@ -0,0 +1,28 @@
1
+ require 'helper'
2
+
3
+ class TestActiveRecord < Test::Unit::TestCase
4
+
5
+ def setup
6
+ load_fixture 'active_record'
7
+ end
8
+
9
+ context 'for activerecord functionality' do
10
+
11
+ should 'check required fields' do
12
+ account = Account.create
13
+ assert ! account.valid?
14
+ end
15
+
16
+ should 'correctly create an account' do
17
+ account = Account.create(:email => "jack@metal.org", :role => "some", :password => "some", :password_confirmation => "some")
18
+ assert account.valid?
19
+ end
20
+
21
+ should 'correctly authenticate an account' do
22
+ account = Account.create(:email => "auth@lipsia.org", :role => "some", :password => "some", :password_confirmation => "some")
23
+ assert_equal "some", account.password_clean
24
+ account_r = Account.authenticate("auth@lipsia.org", "some")
25
+ assert_equal account_r, account
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,38 @@
1
+ require 'helper'
2
+
3
+ class TestAdminApplication < Test::Unit::TestCase
4
+
5
+ def setup
6
+ load_fixture 'data_mapper'
7
+ end
8
+
9
+ should 'set basic roles' do
10
+ mock_app do
11
+ enable :authentication
12
+ set :app_name, :test_me
13
+ set :use_orm, :data_mapper
14
+
15
+ # Do a simple mapping
16
+ access_control.roles_for :any do |role|
17
+ role.allow "/"
18
+ role.deny "/foo"
19
+ end
20
+
21
+ # Prepare a basic page
22
+ get("/login") do
23
+ set_current_account(Account.admin)
24
+ end
25
+
26
+ get("/foo") do
27
+ "foo"
28
+ end
29
+ end
30
+
31
+ get "/login"
32
+ assert_equal 200, status
33
+
34
+ get "/foo"
35
+ assert_not_equal "foo", body
36
+ end
37
+
38
+ end
@@ -0,0 +1,28 @@
1
+ require 'helper'
2
+
3
+ class TestController < Test::Unit::TestCase
4
+
5
+ def setup
6
+ load_fixture 'data_mapper'
7
+ @column_store = Padrino::ExtJs::Controller.column_store_for(Account) do |cm|
8
+ cm.add :name.upcase, "Name Upcase", :sortable => true, :dataIndex => :name
9
+ cm.add :surname # Not exist but it's not a problem
10
+ cm.add :category.name
11
+ cm.add :email, "E-Mail", :sortable => true
12
+ cm.add :role, :sortable => true
13
+ end
14
+ end
15
+
16
+ should 'have correct column fileds' do
17
+ assert_equal nil, @column_store.column_fields
18
+ end
19
+
20
+ should 'have correct store fields' do
21
+ assert_equal nil, @column_store.store_fields
22
+ end
23
+
24
+ should 'store data' do
25
+ assert_equal nil, @column_store.store_data(:fields => "name,role", :query => "d", :sort => :name, :dir => :asc, :limit => 2, :offset => 0)
26
+ end
27
+
28
+ end
@@ -0,0 +1,32 @@
1
+ require 'helper'
2
+
3
+ class TestDataMapper < Test::Unit::TestCase
4
+
5
+ def setup
6
+ load_fixture 'data_mapper'
7
+ end
8
+
9
+ context 'for datamapper functionality' do
10
+
11
+ should 'override default new_record? deprecation' do
12
+ assert Account.new.respond_to?(:new_record?)
13
+ end
14
+
15
+ should 'check required fields' do
16
+ errors = Account.create.errors
17
+ assert_equal [:email, :role, :password, :password_confirmation], errors.keys
18
+ end
19
+
20
+ should 'correctly create an account' do
21
+ account = Account.create(:email => "jack@metal.org", :role => "some", :password => "some", :password_confirmation => "some")
22
+ assert account.valid?
23
+ end
24
+
25
+ should 'correctly authenticate an account' do
26
+ account = Account.create(:email => "auth@lipsia.org", :role => "some", :password => "some", :password_confirmation => "some")
27
+ assert_equal "some", account.password_clean
28
+ account_r = Account.authenticate("auth@lipsia.org", "some")
29
+ assert_equal account_r, account
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,28 @@
1
+ require 'helper'
2
+
3
+ class TestMongoMapper < Test::Unit::TestCase
4
+
5
+ def setup
6
+ load_fixture 'mongo_mapper'
7
+ end
8
+
9
+ context 'for mongomapper functionality' do
10
+
11
+ should 'check required fields' do
12
+ account = Account.create
13
+ assert ! account.valid?
14
+ end
15
+
16
+ should 'correctly create an account' do
17
+ account = Account.create(:email => "jack@metal.org", :role => "some", :password => "some", :password_confirmation => "some")
18
+ assert account.valid?
19
+ end
20
+
21
+ should 'correctly authenticate an account' do
22
+ account = Account.create(:email => "auth@lipsia.org", :role => "some", :password => "some", :password_confirmation => "some")
23
+ assert_equal "some", account.password_clean
24
+ account_r = Account.authenticate("auth@lipsia.org", "some")
25
+ assert_equal account_r, account
26
+ end
27
+ end
28
+ end
data/test/test_parsing.rb CHANGED
@@ -1,9 +1,9 @@
1
- require File.dirname(__FILE__) + '/helper'
1
+ require 'helper'
2
2
 
3
3
  class ParsingTest < Test::Unit::TestCase
4
4
 
5
5
  should "Parse Nested Childs" do
6
- config = ExtJs::Config.load <<-YAML
6
+ config = Padrino::ExtJs::Config.load <<-YAML
7
7
  foo:
8
8
  bar:
9
9
  name: Fred
@@ -13,7 +13,7 @@ class ParsingTest < Test::Unit::TestCase
13
13
  end
14
14
 
15
15
  should "Parse JS and Nested JS" do
16
- config = ExtJs::Config.load <<-YAML
16
+ config = Padrino::ExtJs::Config.load <<-YAML
17
17
  nested:
18
18
  fn: !js function(){ alert('nested fn') }
19
19
  fn: !js function(){ alert('fn') }
@@ -25,11 +25,11 @@ class ParsingTest < Test::Unit::TestCase
25
25
  nested: %nested/fn
26
26
  YAML
27
27
 
28
- assert_kind_of ExtJs::Variable, config["test_one"]
29
- assert_kind_of ExtJs::Variable, config["test_one"]
30
- assert_kind_of ExtJs::Variable, config["test_three"]["no_nested"]
31
- assert_kind_of ExtJs::Variable, config["test_three"]["nested"]
32
- assert_kind_of ExtJs::Variable, config["array"].first
28
+ assert_kind_of Padrino::ExtJs::Variable, config["test_one"]
29
+ assert_kind_of Padrino::ExtJs::Variable, config["test_one"]
30
+ assert_kind_of Padrino::ExtJs::Variable, config["test_three"]["no_nested"]
31
+ assert_kind_of Padrino::ExtJs::Variable, config["test_three"]["nested"]
32
+ assert_kind_of Padrino::ExtJs::Variable, config["array"].first
33
33
 
34
34
  assert_equal "function(){ alert('fn') }", config["test_one"]
35
35
  assert_equal "function(){ alert('nested fn') }", config["test_two"]
@@ -40,7 +40,7 @@ class ParsingTest < Test::Unit::TestCase
40
40
  end
41
41
 
42
42
  should "Parse a multinested YAML" do
43
- config = ExtJs::Config.load <<-YAML
43
+ config = Padrino::ExtJs::Config.load <<-YAML
44
44
  buttons:
45
45
  - id: add
46
46
  text: Add Product
@@ -60,7 +60,7 @@ class ParsingTest < Test::Unit::TestCase
60
60
  end
61
61
 
62
62
  should "Parse array and hashes" do
63
- config = ExtJs::Config.load <<-YAML
63
+ config = Padrino::ExtJs::Config.load <<-YAML
64
64
  a: a
65
65
  b: b
66
66
  c: c
@@ -72,7 +72,7 @@ class ParsingTest < Test::Unit::TestCase
72
72
  end
73
73
 
74
74
  should "Merge config" do
75
- config = ExtJs::Config.load <<-YAML
75
+ config = Padrino::ExtJs::Config.load <<-YAML
76
76
  default:
77
77
  grid:
78
78
  editable: false
@@ -105,7 +105,7 @@ class ParsingTest < Test::Unit::TestCase
105
105
  end
106
106
 
107
107
  should "Merge a complex config" do
108
- config = ExtJs::Config.load <<-YAML
108
+ config = Padrino::ExtJs::Config.load <<-YAML
109
109
  default:
110
110
  grid:
111
111
  editable: false
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: padrino-admin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.9
4
+ version: 0.4.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Padrino Team
@@ -12,18 +12,18 @@ autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
14
 
15
- date: 2009-12-22 00:00:00 -08:00
15
+ date: 2010-01-06 00:00:00 +01:00
16
16
  default_executable:
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
- name: sinatra
19
+ name: json_pure
20
20
  type: :runtime
21
21
  version_requirement:
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 0.9.2
26
+ version: 1.2.0
27
27
  version:
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: padrino-core
@@ -35,6 +35,16 @@ dependencies:
35
35
  - !ruby/object:Gem::Version
36
36
  version: 0.1.1
37
37
  version:
38
+ - !ruby/object:Gem::Dependency
39
+ name: dm-core
40
+ type: :development
41
+ version_requirement:
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: 0.10.2
47
+ version:
38
48
  - !ruby/object:Gem::Dependency
39
49
  name: haml
40
50
  type: :development
@@ -101,11 +111,29 @@ files:
101
111
  - Rakefile
102
112
  - VERSION
103
113
  - lib/padrino-admin.rb
114
+ - lib/padrino-admin/access_control.rb
115
+ - lib/padrino-admin/access_control/helpers.rb
116
+ - lib/padrino-admin/adapters.rb
117
+ - lib/padrino-admin/adapters/ar.rb
118
+ - lib/padrino-admin/adapters/dm.rb
119
+ - lib/padrino-admin/adapters/mm.rb
104
120
  - lib/padrino-admin/ext_js/config.rb
121
+ - lib/padrino-admin/ext_js/controller.rb
105
122
  - lib/padrino-admin/generators/backend.rb
123
+ - lib/padrino-admin/locale/en.yml
124
+ - lib/padrino-admin/support.rb
125
+ - lib/padrino-admin/utils/crypt.rb
106
126
  - padrino-admin.gemspec
127
+ - test/fixtures/active_record.rb
128
+ - test/fixtures/data_mapper.rb
129
+ - test/fixtures/mongo_mapper.rb
107
130
  - test/helper.rb
108
- - test/test_padrino_admin.rb
131
+ - test/test_access_control.rb
132
+ - test/test_active_record.rb
133
+ - test/test_admin_application.rb
134
+ - test/test_controller.rb
135
+ - test/test_data_mapper.rb
136
+ - test/test_mongo_mapper.rb
109
137
  - test/test_parsing.rb
110
138
  has_rdoc: true
111
139
  homepage: http://github.com/padrino/padrino-framework/tree/master/padrino-admin
@@ -1,7 +0,0 @@
1
- require File.dirname(__FILE__) + '/helper'
2
-
3
- class TestPadrinoAdmin < Test::Unit::TestCase
4
- should "probably rename this file and start testing for real" do
5
-
6
- end
7
- end