active_model-password 1.0.0

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,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 196a3392ca7a52ab350848ddaca5810b9d9acf14
4
+ data.tar.gz: d06691a64b9b4a6faec580c9f9278bea29db192c
5
+ SHA512:
6
+ metadata.gz: c9beff8f2e9b5b791b1645d3a020babc5f1eaaee3c408774459e7187ea9908c4643f82d8550b3c085a07a6968152396312be44f7a508797a0d0b2665ad69d118
7
+ data.tar.gz: 5929107214bd6c1833feee6f015d66291effc6af0015b6ef370b6af3136f546c8f90faa9c5e9f122dcd322d4f9388ce848f112979699c5ee7b2f511a8762f5fc
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Kuba Kuźma
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,57 @@
1
+ # ActiveModel::Password
2
+
3
+ `ActiveModel::Password` is a lightweight password model implemented
4
+ on top of `ActiveModel::Model`.
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ gem "active_model-password"
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install active_model-password
19
+
20
+ ## Usage
21
+
22
+ The most popular workflow is:
23
+
24
+ class PasswordsController < ApplicationController
25
+ def edit
26
+ @password = ActiveModel::Password.new
27
+ @password.user = current_user
28
+ end
29
+
30
+ def update
31
+ @password = ActiveModel::Password.new(password_params)
32
+ @password.user = current_user
33
+ if @password.save
34
+ redirect_to root_url, notice: "Password changed successfully."
35
+ else
36
+ render :edit
37
+ end
38
+ end
39
+
40
+ private
41
+
42
+ def password_params
43
+ params.require(:active_model_password).permit(:password, :password_confirmation)
44
+ end
45
+ end
46
+
47
+ If you don't like the default behavior, you can always inherit the
48
+ password model and override some defaults:
49
+
50
+ class Password < ActiveModel::Password
51
+ validates :password, format: {with: /\A(?=.*[a-z])(?=.*[A-Z])(?=.*\d)./}, length: {in: 8..255}, if: -> { password.present? }
52
+ end
53
+
54
+
55
+ ## Copyright
56
+
57
+ Copyright © 2014 Kuba Kuźma. See LICENSE for details.
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.libs += %w[lib test]
6
+ t.test_files = FileList["test/*_test.rb"]
7
+ t.verbose = true
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'active_model/password/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "active_model-password"
8
+ spec.version = ActiveModel::Password::VERSION
9
+ spec.authors = ["Kuba Kuźma"]
10
+ spec.email = ["kuba@jah.pl"]
11
+ spec.summary = %q{Simple password model implemented on top of ActiveModel::Model}
12
+ spec.description = %q{Simple password model implemented on top of ActiveModel::Model}
13
+ spec.homepage = "https://github.com/cowbell/active_model-password"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "activemodel", ">= 4.0.0"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.5"
24
+ spec.add_development_dependency "rake"
25
+ end
@@ -0,0 +1,24 @@
1
+ require "active_model/password/version"
2
+ require "active_model"
3
+
4
+ module ActiveModel
5
+ class Password
6
+ include Model
7
+
8
+ attr_accessor :user, :password
9
+
10
+ validates :user, presence: true
11
+ validates :password, presence: true, confirmation: true
12
+
13
+ def persisted?
14
+ user.present? and user.persisted?
15
+ end
16
+
17
+ def save
18
+ return false unless valid?
19
+ user.password = password
20
+ user.password_confirmation = password_confirmation
21
+ user.save
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,5 @@
1
+ module ActiveModel
2
+ class Password
3
+ VERSION = "1.0.0"
4
+ end
5
+ end
@@ -0,0 +1,75 @@
1
+ require "test_helper"
2
+
3
+ class User
4
+ attr_accessor :password, :password_confirmation, :persisted
5
+
6
+ def save
7
+ password == password_confirmation
8
+ end
9
+
10
+ def persisted?
11
+ !!persisted
12
+ end
13
+ end
14
+
15
+ class PasswordTest < Test::Unit::TestCase
16
+ include ActiveModel::Lint::Tests
17
+
18
+ setup do
19
+ @user = User.new
20
+ @model = @password = ActiveModel::Password.new(user: @user, password: "Password123", password_confirmation: "Password123")
21
+ end
22
+
23
+ test "is valid with valid attributes" do
24
+ assert @password.valid?
25
+ end
26
+
27
+ test "is invalid when user is nil" do
28
+ @password.user = nil
29
+ assert @password.invalid?
30
+ assert @password.errors[:user].present?
31
+ end
32
+
33
+ test "is invalid without password" do
34
+ @password.password = ""
35
+ assert @password.invalid?
36
+ assert @password.errors[:password].present?
37
+ end
38
+
39
+ test "is invalid without password confirmation" do
40
+ @password.password_confirmation = ""
41
+ assert @password.invalid?
42
+ assert @password.errors[:password_confirmation].present?
43
+ end
44
+
45
+ test "is invalid with non-matching password confirmation" do
46
+ @password.password_confirmation = "terces"
47
+ assert @password.invalid?
48
+ assert @password.errors[:password_confirmation].present?
49
+ end
50
+
51
+ test "save returns false if invalid" do
52
+ @password.user = nil
53
+ assert_equal false, @password.save
54
+ end
55
+
56
+ test "save returns true, sets new password" do
57
+ assert @password.save
58
+ assert @user.password = "Password123"
59
+ assert @user.password_confirmation = "Password123"
60
+ end
61
+
62
+ test "persisted returns true if user present and user persisted" do
63
+ @user.persisted = true
64
+ assert @password.persisted?
65
+ end
66
+
67
+ test "persisted returns false if no user present" do
68
+ @password.user = nil
69
+ refute @password.persisted?
70
+ end
71
+
72
+ test "persisted returns false if user present and user not persisted" do
73
+ refute @password.persisted?
74
+ end
75
+ end
@@ -0,0 +1,2 @@
1
+ require "test/unit"
2
+ require "active_model/password"
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: active_model-password
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Kuba Kuźma
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-02-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activemodel
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 4.0.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 4.0.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.5'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.5'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Simple password model implemented on top of ActiveModel::Model
56
+ email:
57
+ - kuba@jah.pl
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - Gemfile
64
+ - LICENSE
65
+ - README.md
66
+ - Rakefile
67
+ - active_model-password.gemspec
68
+ - lib/active_model/password.rb
69
+ - lib/active_model/password/version.rb
70
+ - test/password_test.rb
71
+ - test/test_helper.rb
72
+ homepage: https://github.com/cowbell/active_model-password
73
+ licenses:
74
+ - MIT
75
+ metadata: {}
76
+ post_install_message:
77
+ rdoc_options: []
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ requirements: []
91
+ rubyforge_project:
92
+ rubygems_version: 2.2.0
93
+ signing_key:
94
+ specification_version: 4
95
+ summary: Simple password model implemented on top of ActiveModel::Model
96
+ test_files:
97
+ - test/password_test.rb
98
+ - test/test_helper.rb