File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ gem "nokogiri"
1818gem "feedbag" , github : "dwillis/feedbag"
1919gem "coveralls" , require : false
2020gem "uglifier"
21+ gem "highline" , require : false
2122
2223group :production do
2324 gem "unicorn"
Original file line number Diff line number Diff line change 6969 foreman (0.63.0 )
7070 dotenv (>= 0.7 )
7171 thor (>= 0.13.6 )
72+ highline (1.6.19 )
7273 i18n (0.6.4 )
7374 jsmin (1.0.1 )
7475 kgio (2.8.0 )
@@ -154,6 +155,7 @@ DEPENDENCIES
154155 feedbag !
155156 feedzirra !
156157 foreman
158+ highline
157159 i18n
158160 loofah
159161 nokogiri
Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ Bundler.require
55
66require "./app"
77require_relative "./app/tasks/fetch_feeds"
8+ require_relative "./app/tasks/change_password"
89
910desc "Fetch all feeds."
1011task :fetch_feeds do
@@ -26,6 +27,11 @@ task :work_jobs do
2627 Delayed ::Worker . new ( :min_priority => ENV [ 'MIN_PRIORITY' ] , :max_priority => ENV [ 'MAX_PRIORITY' ] ) . start
2728end
2829
30+ desc "Change your password"
31+ task :change_password do
32+ ChangePassword . new . change_password
33+ end
34+
2935require 'rspec/core/rake_task'
3036
3137RSpec ::Core ::RakeTask . new ( :speedy_tests ) do |t |
Original file line number Diff line number Diff line change 1+ require_relative "../../repositories/user_repository"
2+
3+ class ChangeUserPassword
4+ def initialize ( repository = UserRepository )
5+ @repo = repository
6+ end
7+
8+ def change_user_password ( new_password )
9+ user = @repo . first
10+ user . password = new_password
11+
12+ @repo . save ( user )
13+ user
14+ end
15+ end
Original file line number Diff line number Diff line change @@ -10,4 +10,13 @@ def self.fetch(id)
1010 def self . setup_complete?
1111 User . any? && User . first . setup_complete?
1212 end
13+
14+ def self . save ( user )
15+ user . save
16+ user
17+ end
18+
19+ def self . first
20+ User . first
21+ end
1322end
Original file line number Diff line number Diff line change 1+ require "highline"
2+ require_relative "../commands/users/change_user_password"
3+
4+ class ChangePassword
5+ def initialize ( ui = HighLine . new , command = ChangeUserPassword . new )
6+ @ui = ui
7+ @command = command
8+ end
9+
10+ def change_password
11+ while ( password = ask_password ) != ( confirmation = ask_confirmation )
12+ @ui . say "The confirmation doesn't match the password. Please try again."
13+ end
14+ @command . change_user_password ( password )
15+ end
16+
17+ private
18+ def ask_password
19+ ask_hidden ( "New password: " ) do |q |
20+ q . validate = /\A .+\Z /
21+ q . responses [ :not_valid ] = "The password can't be blank."
22+ end
23+ end
24+
25+ def ask_confirmation
26+ ask_hidden ( "Confirmation: " )
27+ end
28+
29+ def ask_hidden ( question )
30+ @ui . ask ( question ) do |q |
31+ q . echo = "*"
32+ yield ( q ) if block_given?
33+ end
34+ end
35+ end
Original file line number Diff line number Diff line change 11development :
22 adapter : sqlite3
3- database : db/stringer.sqlite
3+ database : db/stringer.sqlite
4+
5+ test :
6+ adapter : sqlite3
7+ database : db/stringer_test.sqlite
Original file line number Diff line number Diff line change 1+ require "spec_helper"
2+ require "support/active_record"
3+
4+ app_require "commands/users/change_user_password"
5+
6+ describe ChangeUserPassword do
7+ let ( :repo ) { stub }
8+ let ( :user ) { User . create ( password : old_password ) }
9+
10+ let ( :old_password ) { "old-pw" }
11+ let ( :new_password ) { "new-pw" }
12+
13+ describe "#change_user_password" do
14+ it "changes the password of the user" do
15+ repo . should_receive ( :first ) . and_return ( user )
16+ repo . should_receive ( :save )
17+
18+ command = ChangeUserPassword . new ( repo )
19+ result = command . change_user_password ( new_password )
20+
21+ BCrypt ::Password . new ( result . password_digest ) . should eq new_password
22+ end
23+ end
24+ end
Original file line number Diff line number Diff line change 11require "spec_helper"
2- require ' support/active_record'
2+ require " support/active_record"
33
44app_require "models/story"
55
Original file line number Diff line number Diff line change 11require 'active_record'
22
3- ActiveRecord ::Base . establish_connection adapter : "sqlite3" , database : "db/stringer_test.sqlite"
3+ config = YAML . load ( File . read ( 'config/database.yml' ) )
4+ ActiveRecord ::Base . establish_connection ( config [ 'test' ] )
45
56def need_to_migrate?
67 current_migration = ActiveRecord ::Migrator . current_version
You can’t perform that action at this time.
0 commit comments