padrino-admin 0.9.26 → 0.9.27

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.
@@ -45,7 +45,6 @@ module Padrino
45
45
  end
46
46
 
47
47
  store_component_choice(:admin_renderer, tmp_ext)
48
- @session_secret = fetch_component_choice(:session_secret)
49
48
 
50
49
  self.behavior = :revoke if options[:destroy]
51
50
 
@@ -1,5 +1,4 @@
1
- class Account < CouchRest::ExtendedDocument
2
- include CouchRest::Validation
1
+ class Account < CouchRest::Model::Base
3
2
  use_database COUCHDB
4
3
 
5
4
  attr_accessor :password, :password_confirmation
@@ -22,9 +21,9 @@ class Account < CouchRest::ExtendedDocument
22
21
  validates_length_of :password, :within => 4..40, :if => :password_required
23
22
  validates_confirmation_of :password, :if => :password_required
24
23
  validates_length_of :email, :within => 3..100
25
- validates_with_method :email, :method => :email_is_unique
26
24
  validates_format_of :email, :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i
27
25
  validates_format_of :role, :with => /[A-Za-z]/
26
+ validate :unique_email_validator
28
27
 
29
28
  # Callbacks
30
29
  before_save :encrypt_password, :if => :password_required
@@ -33,17 +32,8 @@ class Account < CouchRest::ExtendedDocument
33
32
  # This method is for authentication purpose
34
33
  #
35
34
  def self.authenticate(email, password)
36
- email_array = self.by_email :key => email
37
- account = email_array[0]
38
- account && account.has_password?(password) ? account : nil
39
- end
40
-
41
- ##
42
- # This method is used to retrieve the first record by id without raise errors if not found.
43
- #
44
- def self.find_by_id(id)
45
- id_array = self.by_id :key => id
46
- id_array[0]
35
+ account = find_by_email(email)
36
+ account if account && account.has_password?(password)
47
37
  end
48
38
 
49
39
  def has_password?(password)
@@ -59,14 +49,15 @@ class Account < CouchRest::ExtendedDocument
59
49
  crypted_password.blank? || password.present?
60
50
  end
61
51
 
62
- def email_is_unique
63
- account = Account.by_email(:key => self.email, :limit => 1)
64
- return true if account.empty? # didn't find email in the database
65
- account = account[0]
66
- if self.has_key?("_id")
67
- # there is an id, make sure updates are being applied to same account
68
- return true if self["_id"] == account["_id"]
69
- end
70
- [false, "Email has already been taken"]
52
+ def unique_email_validator
53
+ account = Account.find_by_email(email)
54
+
55
+ # didn't find email in the database
56
+ return if account.nil?
57
+
58
+ # account with same email in database is this account
59
+ return if has_key?('_id') && self['_id'] == account['_id']
60
+
61
+ errors.add(:email, "is not unique")
71
62
  end
72
63
  end
@@ -7,9 +7,8 @@ class Account
7
7
  property :id, Serial
8
8
  property :name, String
9
9
  property :surname, String
10
- property :email, String, :length => 100
11
- # BCrypt gives you a 60 character string
12
- property :crypted_password, String, :length => 60
10
+ property :email, String
11
+ property :crypted_password, String
13
12
  property :role, String
14
13
 
15
14
  # Validations
@@ -6,17 +6,18 @@ class Admin < Padrino::Application
6
6
  ##
7
7
  # Application configuration options
8
8
  #
9
- # set :raise_errors, true # Raise exceptions (will stop application) (default true for development)
10
- # set :show_exceptions, true # Show a stack trace in browser (default is true)
9
+ # set :raise_errors, true # Raise exceptions (will stop application) (default for test)
10
+ # set :dump_errors, true # Exception backtraces are written to STDERR (default for production/development)
11
+ # set :show_exceptions, true # Shows a stack trace in browser (default for development)
12
+ # set :logging, true # Logging in STDOUT for development and file for production (default only for development)
11
13
  # set :public, "foo/bar" # Location for static assets (default root/public)
12
14
  # set :reload, false # Reload application files (default in development)
13
15
  # set :default_builder, "foo" # Set a custom form builder (default 'StandardFormBuilder')
14
16
  # set :locale_path, "bar" # Set path for I18n translations (default your_app/locales)
15
- # disable :sessions # Enabled by default
16
- # disable :flash # Disables rack-flash (enabled by default if sessions)
17
+ # disable :sessions # Disabled sessions by default (enable if needed)
18
+ # disable :flash # Disables rack-flash (enabled by default if Rack::Flash is defined)
17
19
  # layout :my_layout # Layout can be in views/layouts/foo.ext or views/foo.ext (default :application)
18
20
  #
19
- set :session_secret, "<%= @session_secret %>"
20
21
  set :login_page, "/admin/sessions/new"
21
22
  disable :store_location
22
23
 
@@ -12,7 +12,7 @@ html lang="en" xmlns="http://www.w3.org/1999/xhtml"
12
12
  #user-navigation
13
13
  ul.wat-cf
14
14
  li==link_to pat(:profile), url(:accounts, :edit, :id => current_account.id)
15
- li==link_to pat(:logout), url(:sessions, :destroy), :method => :delete
15
+ li==button_to pat(:logout), url(:sessions, :destroy), :method => :delete, :class => :button_to
16
16
  #main-navigation
17
17
  ul.wat-cf
18
18
  -project_modules.each do |project_module|
@@ -0,0 +1,38 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../helper')
2
+
3
+ class TestAccountModelGenerator < Test::Unit::TestCase
4
+ def setup
5
+ @apptmp = "#{Dir.tmpdir}/padrino-tests/#{UUID.new.generate}"
6
+ `mkdir -p #{@apptmp}`
7
+ end
8
+
9
+ def teardown
10
+ `rm -rf #{@apptmp}`
11
+ end
12
+
13
+ # COUCHREST
14
+ context 'account model using couchrest' do
15
+ setup do
16
+ silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '-d=couchrest') }
17
+ silence_logger { generate(:admin_app, "--root=#{@apptmp}/sample_project") }
18
+
19
+ @model = "#{@apptmp}/sample_project/app/models/account.rb"
20
+ end
21
+
22
+ should 'be a couchrest model instance' do
23
+ assert_match_in_file(/class Account < CouchRest::Model::Base/m, @model)
24
+ end
25
+
26
+ should 'not require additional validations' do
27
+ assert_no_match_in_file(/include CouchRest::Validation/m, @model)
28
+ end
29
+
30
+ should 'no longer have validates_with_method' do
31
+ assert_no_match_in_file(/validates_with_method/m, @model)
32
+ end
33
+
34
+ should 'validate report errors using ActiveModel errors method' do
35
+ assert_match_in_file(/errors\.add\(:email, "is not unique"\)/m, @model)
36
+ end
37
+ end
38
+ end
@@ -58,7 +58,7 @@ class TestAdminAppGenerator < Test::Unit::TestCase
58
58
  assert_match_in_file 'Padrino.mount("Admin").to("/admin")', "#{@apptmp}/sample_project/config/apps.rb"
59
59
  assert_match_in_file 'class Admin < Padrino::Application', "#{@apptmp}/sample_project/admin/app.rb"
60
60
  assert_match_in_file 'role.project_module :accounts, "/accounts"', "#{@apptmp}/sample_project/admin/app.rb"
61
- assert_match_in_file 'set :session_secret, "', "#{@apptmp}/sample_project/admin/app.rb"
61
+ assert_match_in_file 'button_to pat(:logout)', "#{@apptmp}/sample_project/admin/views/layouts/application.haml"
62
62
  end
63
63
 
64
64
  should 'correctly generate a new padrino admin application with erb renderer' do
@@ -90,7 +90,7 @@ class TestAdminAppGenerator < Test::Unit::TestCase
90
90
  assert_match_in_file 'Padrino.mount("Admin").to("/admin")', "#{@apptmp}/sample_project/config/apps.rb"
91
91
  assert_match_in_file 'class Admin < Padrino::Application', "#{@apptmp}/sample_project/admin/app.rb"
92
92
  assert_match_in_file 'role.project_module :accounts, "/accounts"', "#{@apptmp}/sample_project/admin/app.rb"
93
- assert_match_in_file 'set :session_secret, "', "#{@apptmp}/sample_project/admin/app.rb"
93
+ assert_match_in_file 'button_to pat(:logout)', "#{@apptmp}/sample_project/admin/views/layouts/application.erb"
94
94
  end
95
95
 
96
96
  should 'correctly generate a new padrino admin application with slim renderer' do
@@ -122,7 +122,7 @@ class TestAdminAppGenerator < Test::Unit::TestCase
122
122
  assert_match_in_file 'Padrino.mount("Admin").to("/admin")', "#{@apptmp}/sample_project/config/apps.rb"
123
123
  assert_match_in_file 'class Admin < Padrino::Application', "#{@apptmp}/sample_project/admin/app.rb"
124
124
  assert_match_in_file 'role.project_module :accounts, "/accounts"', "#{@apptmp}/sample_project/admin/app.rb"
125
- assert_match_in_file 'set :session_secret, "', "#{@apptmp}/sample_project/admin/app.rb"
125
+ assert_match_in_file 'button_to pat(:logout)', "#{@apptmp}/sample_project/admin/views/layouts/application.slim"
126
126
  end
127
127
 
128
128
  should 'not conflict with existing seeds file' do
@@ -143,5 +143,12 @@ class TestAdminAppGenerator < Test::Unit::TestCase
143
143
  assert_match_in_file '# Old Seeds Content', "#{@apptmp}/sample_project/db/seeds.rb"
144
144
  assert_match_in_file 'Account.create(', "#{@apptmp}/sample_project/db/seeds.rb"
145
145
  end
146
+
147
+ should "navigate completely inside an app with activerecord" do
148
+ silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", "-d=activerecord", "-e=haml", "--dev") }
149
+ silence_logger { generate(:admin_app, "--root=#{@apptmp}/sample_project") }
150
+ # bundle(:install, :gemfile => "#{@apptmp}/sample_project/Gemfile", :path => "#{@apptmp}/bundle")
151
+ # cli(:rake, '-T', "-c=#{@apptmp}/sample_project")
152
+ end
146
153
  end
147
154
  end
@@ -58,12 +58,7 @@ class TestAdminPageGenerator < Test::Unit::TestCase
58
58
 
59
59
  should "store and apply session_secret" do
60
60
  silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '-d=datamapper','-e=haml') }
61
- silence_logger { generate(:admin_app, "--root=#{@apptmp}/sample_project") }
62
- assert_match_in_file(/session_secret:.+/, "#{@apptmp}/sample_project/.components")
63
- session_secret = YAML.load_file("#{@apptmp}/sample_project/.components")[:session_secret]
64
- assert_not_equal "", session_secret
65
- assert_match_in_file(/#{session_secret}/, "#{@apptmp}/sample_project/app/app.rb")
66
- assert_match_in_file(/#{session_secret}/, "#{@apptmp}/sample_project/admin/app.rb")
61
+ assert_match_in_file(/set :session_secret, '[0-9A-z]*'/, "#{@apptmp}/sample_project/config/apps.rb")
67
62
  end
68
63
 
69
64
  should 'correctly generate a new padrino admin application with erb renderer' do
@@ -243,4 +243,4 @@ class TestAdminApplication < Test::Unit::TestCase
243
243
  get "/modules"
244
244
  assert_equal "admin => /admin", body
245
245
  end
246
- end unless RUBY_PLATFORM =~ /java/ # DM seems to have some problems on JRuby
246
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: padrino-admin
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
4
+ hash: 13
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 9
9
- - 26
10
- version: 0.9.26
9
+ - 27
10
+ version: 0.9.27
11
11
  platform: ruby
12
12
  authors:
13
13
  - Padrino Team
@@ -18,7 +18,7 @@ autorequire:
18
18
  bindir: bin
19
19
  cert_chain: []
20
20
 
21
- date: 2011-04-28 00:00:00 Z
21
+ date: 2011-05-06 00:00:00 Z
22
22
  dependencies:
23
23
  - !ruby/object:Gem::Dependency
24
24
  name: padrino-core
@@ -28,12 +28,12 @@ dependencies:
28
28
  requirements:
29
29
  - - "="
30
30
  - !ruby/object:Gem::Version
31
- hash: 15
31
+ hash: 13
32
32
  segments:
33
33
  - 0
34
34
  - 9
35
- - 26
36
- version: 0.9.26
35
+ - 27
36
+ version: 0.9.27
37
37
  type: :runtime
38
38
  version_requirements: *id001
39
39
  - !ruby/object:Gem::Dependency
@@ -44,12 +44,12 @@ dependencies:
44
44
  requirements:
45
45
  - - "="
46
46
  - !ruby/object:Gem::Version
47
- hash: 15
47
+ hash: 13
48
48
  segments:
49
49
  - 0
50
50
  - 9
51
- - 26
52
- version: 0.9.26
51
+ - 27
52
+ version: 0.9.27
53
53
  type: :runtime
54
54
  version_requirements: *id002
55
55
  description: Admin View for Padrino applications
@@ -159,6 +159,7 @@ files:
159
159
  - lib/padrino-admin/utils/crypt.rb
160
160
  - padrino-admin.gemspec
161
161
  - test/fixtures/data_mapper.rb
162
+ - test/generators/test_account_model_generator.rb
162
163
  - test/generators/test_admin_app_generator.rb
163
164
  - test/generators/test_admin_page_generator.rb
164
165
  - test/helper.rb
@@ -200,6 +201,7 @@ specification_version: 3
200
201
  summary: Admin Dashboard for Padrino
201
202
  test_files:
202
203
  - test/fixtures/data_mapper.rb
204
+ - test/generators/test_account_model_generator.rb
203
205
  - test/generators/test_admin_app_generator.rb
204
206
  - test/generators/test_admin_page_generator.rb
205
207
  - test/helper.rb