rails_magic_renamer 2.0.0.pre.alpha

Sign up to get free protection for your applications and to get access to all the features.
Files changed (164) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +2 -0
  3. data/.ruby-version +1 -0
  4. data/.travis.yml +6 -0
  5. data/CHANGELOG +4 -0
  6. data/Gemfile +4 -0
  7. data/Gemfile.lock +173 -0
  8. data/Guardfile +11 -0
  9. data/Manifest +8 -0
  10. data/README.md +59 -0
  11. data/ROADMAP.md +60 -0
  12. data/Rakefile +2 -0
  13. data/lib/rails_magic_renamer.rb +343 -0
  14. data/lib/rails_magic_renamer/exceptions.rb +35 -0
  15. data/lib/rails_magic_renamer/version.rb +3 -0
  16. data/rails_magic_renamer.gemspec +36 -0
  17. data/spec/rails_helper.rb +26 -0
  18. data/spec/rails_magic_renamer_spec.rb +22 -0
  19. data/spec/spec_helper.rb +17 -0
  20. data/spec/support/sample_app_rails_4/.gitignore +19 -0
  21. data/spec/support/sample_app_rails_4/.rspec +2 -0
  22. data/spec/support/sample_app_rails_4/Gemfile +58 -0
  23. data/spec/support/sample_app_rails_4/Gemfile.lock +249 -0
  24. data/spec/support/sample_app_rails_4/Guardfile +53 -0
  25. data/spec/support/sample_app_rails_4/LICENSE +21 -0
  26. data/spec/support/sample_app_rails_4/README.md +25 -0
  27. data/spec/support/sample_app_rails_4/README.nitrous.md +20 -0
  28. data/spec/support/sample_app_rails_4/Rakefile +6 -0
  29. data/spec/support/sample_app_rails_4/app/assets/images/rails.png +0 -0
  30. data/spec/support/sample_app_rails_4/app/assets/javascripts/application.js +17 -0
  31. data/spec/support/sample_app_rails_4/app/assets/javascripts/sessions.js.coffee +3 -0
  32. data/spec/support/sample_app_rails_4/app/assets/javascripts/static_pages.js.coffee +3 -0
  33. data/spec/support/sample_app_rails_4/app/assets/javascripts/users.js.coffee +3 -0
  34. data/spec/support/sample_app_rails_4/app/assets/stylesheets/application.css +13 -0
  35. data/spec/support/sample_app_rails_4/app/assets/stylesheets/custom.css.scss +246 -0
  36. data/spec/support/sample_app_rails_4/app/assets/stylesheets/sessions.css.scss +3 -0
  37. data/spec/support/sample_app_rails_4/app/assets/stylesheets/static_pages.css.scss +3 -0
  38. data/spec/support/sample_app_rails_4/app/assets/stylesheets/users.css.scss +3 -0
  39. data/spec/support/sample_app_rails_4/app/controllers/application_controller.rb +6 -0
  40. data/spec/support/sample_app_rails_4/app/controllers/concerns/.keep +0 -0
  41. data/spec/support/sample_app_rails_4/app/controllers/microposts_controller.rb +31 -0
  42. data/spec/support/sample_app_rails_4/app/controllers/relationships_controller.rb +21 -0
  43. data/spec/support/sample_app_rails_4/app/controllers/sessions_controller.rb +21 -0
  44. data/spec/support/sample_app_rails_4/app/controllers/static_pages_controller.rb +18 -0
  45. data/spec/support/sample_app_rails_4/app/controllers/users_controller.rb +80 -0
  46. data/spec/support/sample_app_rails_4/app/helpers/application_helper.rb +12 -0
  47. data/spec/support/sample_app_rails_4/app/helpers/sessions_helper.rb +49 -0
  48. data/spec/support/sample_app_rails_4/app/helpers/static_pages_helper.rb +2 -0
  49. data/spec/support/sample_app_rails_4/app/helpers/users_helper.rb +10 -0
  50. data/spec/support/sample_app_rails_4/app/mailers/.keep +0 -0
  51. data/spec/support/sample_app_rails_4/app/models/.keep +0 -0
  52. data/spec/support/sample_app_rails_4/app/models/comment.rb +5 -0
  53. data/spec/support/sample_app_rails_4/app/models/concerns/.keep +0 -0
  54. data/spec/support/sample_app_rails_4/app/models/micropost.rb +14 -0
  55. data/spec/support/sample_app_rails_4/app/models/organisation.rb +3 -0
  56. data/spec/support/sample_app_rails_4/app/models/relationship.rb +6 -0
  57. data/spec/support/sample_app_rails_4/app/models/user.rb +57 -0
  58. data/spec/support/sample_app_rails_4/app/models/user_comment.rb +5 -0
  59. data/spec/support/sample_app_rails_4/app/views/layouts/_footer.html.erb +13 -0
  60. data/spec/support/sample_app_rails_4/app/views/layouts/_header.html.erb +31 -0
  61. data/spec/support/sample_app_rails_4/app/views/layouts/_shim.html.erb +3 -0
  62. data/spec/support/sample_app_rails_4/app/views/layouts/application.html.erb +22 -0
  63. data/spec/support/sample_app_rails_4/app/views/microposts/_micropost.html.erb +11 -0
  64. data/spec/support/sample_app_rails_4/app/views/relationships/create.js.erb +2 -0
  65. data/spec/support/sample_app_rails_4/app/views/relationships/destroy.js.erb +2 -0
  66. data/spec/support/sample_app_rails_4/app/views/sessions/new.html.erb +19 -0
  67. data/spec/support/sample_app_rails_4/app/views/shared/_error_messages.html.erb +12 -0
  68. data/spec/support/sample_app_rails_4/app/views/shared/_feed.html.erb +6 -0
  69. data/spec/support/sample_app_rails_4/app/views/shared/_feed_item.html.erb +15 -0
  70. data/spec/support/sample_app_rails_4/app/views/shared/_micropost_form.html.erb +7 -0
  71. data/spec/support/sample_app_rails_4/app/views/shared/_stats.html.erb +15 -0
  72. data/spec/support/sample_app_rails_4/app/views/shared/_user_info.html.erb +12 -0
  73. data/spec/support/sample_app_rails_4/app/views/static_pages/about.html.erb +8 -0
  74. data/spec/support/sample_app_rails_4/app/views/static_pages/contact.html.erb +6 -0
  75. data/spec/support/sample_app_rails_4/app/views/static_pages/help.html.erb +8 -0
  76. data/spec/support/sample_app_rails_4/app/views/static_pages/home.html.erb +34 -0
  77. data/spec/support/sample_app_rails_4/app/views/static_pages/show.html.erb +0 -0
  78. data/spec/support/sample_app_rails_4/app/views/users/_follow.html.erb +5 -0
  79. data/spec/support/sample_app_rails_4/app/views/users/_follow_form.html.erb +9 -0
  80. data/spec/support/sample_app_rails_4/app/views/users/_unfollow.html.erb +5 -0
  81. data/spec/support/sample_app_rails_4/app/views/users/_user.html.erb +8 -0
  82. data/spec/support/sample_app_rails_4/app/views/users/edit.html.erb +27 -0
  83. data/spec/support/sample_app_rails_4/app/views/users/index.html.erb +10 -0
  84. data/spec/support/sample_app_rails_4/app/views/users/new.html.erb +24 -0
  85. data/spec/support/sample_app_rails_4/app/views/users/show.html.erb +24 -0
  86. data/spec/support/sample_app_rails_4/app/views/users/show_follow.html.erb +30 -0
  87. data/spec/support/sample_app_rails_4/bin/bundle +3 -0
  88. data/spec/support/sample_app_rails_4/bin/rails +4 -0
  89. data/spec/support/sample_app_rails_4/bin/rake +4 -0
  90. data/spec/support/sample_app_rails_4/config.ru +4 -0
  91. data/spec/support/sample_app_rails_4/config/application.rb +31 -0
  92. data/spec/support/sample_app_rails_4/config/boot.rb +4 -0
  93. data/spec/support/sample_app_rails_4/config/cucumber.yml +8 -0
  94. data/spec/support/sample_app_rails_4/config/database.yml +12 -0
  95. data/spec/support/sample_app_rails_4/config/environment.rb +7 -0
  96. data/spec/support/sample_app_rails_4/config/environments/development.rb +27 -0
  97. data/spec/support/sample_app_rails_4/config/environments/production.rb +79 -0
  98. data/spec/support/sample_app_rails_4/config/environments/test.rb +39 -0
  99. data/spec/support/sample_app_rails_4/config/initializers/backtrace_silencers.rb +7 -0
  100. data/spec/support/sample_app_rails_4/config/initializers/filter_parameter_logging.rb +4 -0
  101. data/spec/support/sample_app_rails_4/config/initializers/inflections.rb +16 -0
  102. data/spec/support/sample_app_rails_4/config/initializers/mime_types.rb +5 -0
  103. data/spec/support/sample_app_rails_4/config/initializers/secret_token.rb +22 -0
  104. data/spec/support/sample_app_rails_4/config/initializers/session_store.rb +3 -0
  105. data/spec/support/sample_app_rails_4/config/initializers/wrap_parameters.rb +14 -0
  106. data/spec/support/sample_app_rails_4/config/locales/en.yml +23 -0
  107. data/spec/support/sample_app_rails_4/config/routes.rb +17 -0
  108. data/spec/support/sample_app_rails_4/db/development.sqlite3 +0 -0
  109. data/spec/support/sample_app_rails_4/db/migrate/20130311191400_create_users.rb +10 -0
  110. data/spec/support/sample_app_rails_4/db/migrate/20130311194153_add_index_to_users_email.rb +5 -0
  111. data/spec/support/sample_app_rails_4/db/migrate/20130311201841_add_password_digest_to_users.rb +5 -0
  112. data/spec/support/sample_app_rails_4/db/migrate/20130314184954_add_remember_token_to_users.rb +6 -0
  113. data/spec/support/sample_app_rails_4/db/migrate/20130315015932_add_admin_to_users.rb +5 -0
  114. data/spec/support/sample_app_rails_4/db/migrate/20130315175534_create_microposts.rb +11 -0
  115. data/spec/support/sample_app_rails_4/db/migrate/20130315230445_create_relationships.rb +13 -0
  116. data/spec/support/sample_app_rails_4/db/migrate/20160424113439_create_comments.rb +8 -0
  117. data/spec/support/sample_app_rails_4/db/migrate/20160424113451_create_user_comments.rb +8 -0
  118. data/spec/support/sample_app_rails_4/db/migrate/20160424114701_create_organisations.rb +8 -0
  119. data/spec/support/sample_app_rails_4/db/migrate/20160424114727_add_organisation_id_to_users.rb +5 -0
  120. data/spec/support/sample_app_rails_4/db/schema.rb +67 -0
  121. data/spec/support/sample_app_rails_4/db/seeds.rb +7 -0
  122. data/spec/support/sample_app_rails_4/db/test.sqlite3 +0 -0
  123. data/spec/support/sample_app_rails_4/factory_girl.rb +7 -0
  124. data/spec/support/sample_app_rails_4/features/signing_in.feature +13 -0
  125. data/spec/support/sample_app_rails_4/features/step_definitions/authentication_steps.rb +30 -0
  126. data/spec/support/sample_app_rails_4/features/support/env.rb +59 -0
  127. data/spec/support/sample_app_rails_4/lib/assets/.keep +0 -0
  128. data/spec/support/sample_app_rails_4/lib/tasks/.keep +0 -0
  129. data/spec/support/sample_app_rails_4/lib/tasks/cucumber.rake +65 -0
  130. data/spec/support/sample_app_rails_4/lib/tasks/sample_data.rake +42 -0
  131. data/spec/support/sample_app_rails_4/log/.keep +0 -0
  132. data/spec/support/sample_app_rails_4/public/404.html +27 -0
  133. data/spec/support/sample_app_rails_4/public/422.html +26 -0
  134. data/spec/support/sample_app_rails_4/public/500.html +26 -0
  135. data/spec/support/sample_app_rails_4/public/assets/application-4962059d8f80f9bb096692bacc29c4e8.css +5091 -0
  136. data/spec/support/sample_app_rails_4/public/assets/application-4962059d8f80f9bb096692bacc29c4e8.css.gz +0 -0
  137. data/spec/support/sample_app_rails_4/public/assets/application-eeb856e3fe2c8f879c91d0e81d59cb40.js +12952 -0
  138. data/spec/support/sample_app_rails_4/public/assets/application-eeb856e3fe2c8f879c91d0e81d59cb40.js.gz +0 -0
  139. data/spec/support/sample_app_rails_4/public/assets/glyphicons-halflings-c806376f05e4ccabe2c5315a8e95667c.png +0 -0
  140. data/spec/support/sample_app_rails_4/public/assets/glyphicons-halflings-white-62b67d9edee3db90d18833087f848d6e.png +0 -0
  141. data/spec/support/sample_app_rails_4/public/assets/manifest-802de9eb1c853769101852422b620883.json +1 -0
  142. data/spec/support/sample_app_rails_4/public/assets/rails-231a680f23887d9dd70710ea5efd3c62.png +0 -0
  143. data/spec/support/sample_app_rails_4/public/favicon.ico +0 -0
  144. data/spec/support/sample_app_rails_4/public/robots.txt +5 -0
  145. data/spec/support/sample_app_rails_4/script/cucumber +10 -0
  146. data/spec/support/sample_app_rails_4/spec/controllers/relationships_controller_spec.rb +42 -0
  147. data/spec/support/sample_app_rails_4/spec/factories.rb +17 -0
  148. data/spec/support/sample_app_rails_4/spec/features/authentication_pages_spec.rb +155 -0
  149. data/spec/support/sample_app_rails_4/spec/features/micropost_pages_spec.rb +45 -0
  150. data/spec/support/sample_app_rails_4/spec/features/static_pages_spec.rb +64 -0
  151. data/spec/support/sample_app_rails_4/spec/features/user_pages_spec.rb +239 -0
  152. data/spec/support/sample_app_rails_4/spec/helpers/application_helper_spec.rb +18 -0
  153. data/spec/support/sample_app_rails_4/spec/models/comments_spec.rb +5 -0
  154. data/spec/support/sample_app_rails_4/spec/models/micropost_spec.rb +30 -0
  155. data/spec/support/sample_app_rails_4/spec/models/organisation_spec.rb +5 -0
  156. data/spec/support/sample_app_rails_4/spec/models/relationship_spec.rb +36 -0
  157. data/spec/support/sample_app_rails_4/spec/models/user_comments_spec.rb +5 -0
  158. data/spec/support/sample_app_rails_4/spec/models/user_spec.rb +108 -0
  159. data/spec/support/sample_app_rails_4/spec/spec_helper.rb +57 -0
  160. data/spec/support/sample_app_rails_4/spec/support/utilities.rb +21 -0
  161. data/spec/support/sample_app_rails_4/vendor/assets/javascripts/.keep +0 -0
  162. data/spec/support/sample_app_rails_4/vendor/assets/stylesheets/.keep +0 -0
  163. data/tasks/rspec.rake +4 -0
  164. metadata +534 -0
@@ -0,0 +1,6 @@
1
+ class ApplicationController < ActionController::Base
2
+ # Prevent CSRF attacks by raising an exception.
3
+ # For APIs, you may want to use :null_session instead.
4
+ protect_from_forgery with: :exception
5
+ include SessionsHelper
6
+ end
@@ -0,0 +1,31 @@
1
+ class MicropostsController < ApplicationController
2
+ before_action :signed_in_user, only: [:create, :destroy]
3
+ before_action :correct_user, only: :destroy
4
+
5
+ def create
6
+ @micropost = current_user.microposts.build(micropost_params)
7
+ if @micropost.save
8
+ flash[:success] = "Micropost created!"
9
+ redirect_to root_url
10
+ else
11
+ @feed_items = []
12
+ render 'static_pages/home'
13
+ end
14
+ end
15
+
16
+ def destroy
17
+ @micropost.destroy
18
+ redirect_to root_url
19
+ end
20
+
21
+ private
22
+
23
+ def micropost_params
24
+ params.require(:micropost).permit(:content)
25
+ end
26
+
27
+ def correct_user
28
+ @micropost = current_user.microposts.find_by(id: params[:id])
29
+ redirect_to root_url if @micropost.nil?
30
+ end
31
+ end
@@ -0,0 +1,21 @@
1
+ class RelationshipsController < ApplicationController
2
+ before_action :signed_in_user
3
+
4
+ def create
5
+ @user = User.find(params[:relationship][:followed_id])
6
+ current_user.follow!(@user)
7
+ respond_to do |format|
8
+ format.html { redirect_to @user }
9
+ format.js
10
+ end
11
+ end
12
+
13
+ def destroy
14
+ @user = Relationship.find(params[:id]).followed
15
+ current_user.unfollow!(@user)
16
+ respond_to do |format|
17
+ format.html { redirect_to @user }
18
+ format.js
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ class SessionsController < ApplicationController
2
+
3
+ def new
4
+ end
5
+
6
+ def create
7
+ user = User.find_by(email: params[:session][:email].downcase)
8
+ if user && user.authenticate(params[:session][:password])
9
+ sign_in user
10
+ redirect_back_or user
11
+ else
12
+ flash.now[:error] = 'Invalid email/password combination'
13
+ render 'new'
14
+ end
15
+ end
16
+
17
+ def destroy
18
+ sign_out
19
+ redirect_to root_url
20
+ end
21
+ end
@@ -0,0 +1,18 @@
1
+ class StaticPagesController < ApplicationController
2
+
3
+ def home
4
+ if signed_in?
5
+ @micropost = current_user.microposts.build
6
+ @feed_items = current_user.feed.paginate(page: params[:page])
7
+ end
8
+ end
9
+
10
+ def help
11
+ end
12
+
13
+ def about
14
+ end
15
+
16
+ def contact
17
+ end
18
+ end
@@ -0,0 +1,80 @@
1
+ class UsersController < ApplicationController
2
+ before_action :signed_in_user,
3
+ only: [:index, :edit, :update, :destroy, :following, :followers]
4
+ before_action :correct_user, only: [:edit, :update]
5
+ before_action :admin_user, only: :destroy
6
+
7
+ def index
8
+ @users = User.paginate(page: params[:page])
9
+ end
10
+
11
+ def show
12
+ @user = User.find(params[:id])
13
+ @microposts = @user.microposts.paginate(page: params[:page])
14
+ end
15
+
16
+ def new
17
+ @user = User.new
18
+ end
19
+
20
+ def create
21
+ @user = User.new(user_params)
22
+ if @user.save
23
+ sign_in @user
24
+ flash[:success] = "Welcome to the Sample App!"
25
+ redirect_to @user
26
+ else
27
+ render 'new'
28
+ end
29
+ end
30
+
31
+ def edit
32
+ end
33
+
34
+ def update
35
+ if @user.update_attributes(user_params)
36
+ flash[:success] = "Profile updated"
37
+ redirect_to @user
38
+ else
39
+ render 'edit'
40
+ end
41
+ end
42
+
43
+ def destroy
44
+ User.find(params[:id]).destroy
45
+ flash[:success] = "User destroyed."
46
+ redirect_to users_url
47
+ end
48
+
49
+ def following
50
+ @title = "Following"
51
+ @user = User.find(params[:id])
52
+ @users = @user.followed_users.paginate(page: params[:page])
53
+ render 'show_follow'
54
+ end
55
+
56
+ def followers
57
+ @title = "Followers"
58
+ @user = User.find(params[:id])
59
+ @users = @user.followers.paginate(page: params[:page])
60
+ render 'show_follow'
61
+ end
62
+
63
+ private
64
+
65
+ def user_params
66
+ params.require(:user).permit(:name, :email, :password,
67
+ :password_confirmation)
68
+ end
69
+
70
+ # Before filters
71
+
72
+ def correct_user
73
+ @user = User.find(params[:id])
74
+ redirect_to(root_url) unless current_user?(@user)
75
+ end
76
+
77
+ def admin_user
78
+ redirect_to(root_url) unless current_user.admin?
79
+ end
80
+ end
@@ -0,0 +1,12 @@
1
+ module ApplicationHelper
2
+
3
+ # Returns the full title on a per-page basis.
4
+ def full_title(page_title)
5
+ base_title = "Ruby on Rails Tutorial Sample App"
6
+ if page_title.empty?
7
+ base_title
8
+ else
9
+ "#{base_title} | #{page_title}"
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,49 @@
1
+ module SessionsHelper
2
+
3
+ def sign_in(user)
4
+ remember_token = User.new_remember_token
5
+ cookies.permanent[:remember_token] = remember_token
6
+ user.update_attribute(:remember_token, User.digest(remember_token))
7
+ self.current_user = user
8
+ end
9
+
10
+ def signed_in?
11
+ !current_user.nil?
12
+ end
13
+
14
+ def current_user=(user)
15
+ @current_user = user
16
+ end
17
+
18
+ def current_user
19
+ remember_token = User.digest(cookies[:remember_token])
20
+ @current_user ||= User.find_by(remember_token: remember_token)
21
+ end
22
+
23
+ def current_user?(user)
24
+ user == current_user
25
+ end
26
+
27
+ def signed_in_user
28
+ unless signed_in?
29
+ store_location
30
+ redirect_to signin_url, notice: "Please sign in."
31
+ end
32
+ end
33
+
34
+ def sign_out
35
+ current_user.update_attribute(:remember_token,
36
+ User.digest(User.new_remember_token))
37
+ cookies.delete(:remember_token)
38
+ self.current_user = nil
39
+ end
40
+
41
+ def redirect_back_or(default)
42
+ redirect_to(session[:return_to] || default)
43
+ session.delete(:return_to)
44
+ end
45
+
46
+ def store_location
47
+ session[:return_to] = request.url if request.get?
48
+ end
49
+ end
@@ -0,0 +1,2 @@
1
+ module StaticPagesHelper
2
+ end
@@ -0,0 +1,10 @@
1
+ module UsersHelper
2
+
3
+ # Returns the Gravatar (http://gravatar.com/) for the given user.
4
+ def gravatar_for(user, options = { size: 50 })
5
+ gravatar_id = Digest::MD5::hexdigest(user.email.downcase)
6
+ size = options[:size]
7
+ gravatar_url = "https://secure.gravatar.com/avatar/#{gravatar_id}?s=#{size}"
8
+ image_tag(gravatar_url, alt: user.name, class: "gravatar")
9
+ end
10
+ end
File without changes
File without changes
@@ -0,0 +1,5 @@
1
+ class Comment < ActiveRecord::Base
2
+
3
+ has_many :user_comments
4
+ has_many :users, through: :user_comments
5
+ end
@@ -0,0 +1,14 @@
1
+ class Micropost < ActiveRecord::Base
2
+ belongs_to :user
3
+ default_scope -> { order('created_at DESC') }
4
+ validates :content, presence: true, length: { maximum: 140 }
5
+ validates :user_id, presence: true
6
+
7
+ # Returns microposts from the users being followed by the given user.
8
+ def self.from_users_followed_by(user)
9
+ followed_user_ids = "SELECT followed_id FROM relationships
10
+ WHERE follower_id = :user_id"
11
+ where("user_id IN (#{followed_user_ids}) OR user_id = :user_id",
12
+ user_id: user.id)
13
+ end
14
+ end
@@ -0,0 +1,3 @@
1
+ class Organisation < ActiveRecord::Base
2
+ has_many :users
3
+ end
@@ -0,0 +1,6 @@
1
+ class Relationship < ActiveRecord::Base
2
+ belongs_to :follower, class_name: "User"
3
+ belongs_to :followed, class_name: "User"
4
+ validates :follower_id, presence: true
5
+ validates :followed_id, presence: true
6
+ end
@@ -0,0 +1,57 @@
1
+ class User < ActiveRecord::Base
2
+ has_many :microposts, dependent: :destroy
3
+ has_many :relationships, foreign_key: "follower_id", dependent: :destroy
4
+ has_many :followed_users, through: :relationships, source: :followed
5
+ has_many :reverse_relationships, foreign_key: "followed_id",
6
+ class_name: "Relationship",
7
+ dependent: :destroy
8
+ has_many :followers, through: :reverse_relationships, source: :follower
9
+
10
+ has_many :user_comments
11
+ has_many :comments, through: :user_comments
12
+
13
+ belongs_to :organisation
14
+
15
+ before_save { self.email = email.downcase }
16
+ before_create :create_remember_token
17
+ validates :name, presence: true, length: { maximum: 50 }
18
+ VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-]+(\.[a-z]+)*\.[a-z]+\z/i
19
+ validates :email, presence: true, format: { with: VALID_EMAIL_REGEX },
20
+ uniqueness: { case_sensitive: false }
21
+ attr_accessor :password, :password_confirmation
22
+ validates :password, length: { minimum: 6 }
23
+
24
+ def User.new_remember_token
25
+ SecureRandom.urlsafe_base64
26
+ end
27
+
28
+ def User.digest(token)
29
+ Digest::SHA1.hexdigest(token.to_s)
30
+ end
31
+
32
+ def feed
33
+ Micropost.from_users_followed_by(self)
34
+ end
35
+
36
+ def following?(other_user)
37
+ relationships.find_by(followed_id: other_user.id)
38
+ end
39
+
40
+ def follow!(other_user)
41
+ relationships.create!(followed_id: other_user.id)
42
+ end
43
+
44
+ def unfollow!(other_user)
45
+ relationships.find_by(followed_id: other_user.id).destroy
46
+ end
47
+
48
+ def authenticate(password = true)
49
+ return self
50
+ end
51
+
52
+ private
53
+
54
+ def create_remember_token
55
+ self.remember_token = User.digest(User.new_remember_token)
56
+ end
57
+ end
@@ -0,0 +1,5 @@
1
+ class UserComment < ActiveRecord::Base
2
+
3
+ belongs_to :user
4
+ belongs_to :comment
5
+ end
@@ -0,0 +1,13 @@
1
+ <footer class="footer">
2
+ <small>
3
+ <a href="http://railstutorial.org/">Rails Tutorial</a>
4
+ by Michael Hartl
5
+ </small>
6
+ <nav>
7
+ <ul>
8
+ <li><%= link_to "About", about_path %></li>
9
+ <li><%= link_to "Contact", contact_path %></li>
10
+ <li><a href="http://news.railstutorial.org/">News</a></li>
11
+ </ul>
12
+ </nav>
13
+ </footer>
@@ -0,0 +1,31 @@
1
+ <header class="navbar navbar-fixed-top navbar-inverse">
2
+ <div class="navbar-inner">
3
+ <div class="container">
4
+ <%= link_to "sample app", root_path, id: "logo" %>
5
+ <nav>
6
+ <ul class="nav pull-right">
7
+ <li><%= link_to "Home", root_path %></li>
8
+ <li><%= link_to "Help", help_path %></li>
9
+ <% if signed_in? %>
10
+ <li><%= link_to "Users", users_path %></li>
11
+ <li id="fat-menu" class="dropdown">
12
+ <a href="#" class="dropdown-toggle" data-toggle="dropdown">
13
+ Account <b class="caret"></b>
14
+ </a>
15
+ <ul class="dropdown-menu">
16
+ <li><%= link_to "Profile", current_user %></li>
17
+ <li><%= link_to "Settings", edit_user_path(current_user) %></li>
18
+ <li class="divider"></li>
19
+ <li>
20
+ <%= link_to "Sign out", signout_path, method: "delete" %>
21
+ </li>
22
+ </ul>
23
+ </li>
24
+ <% else %>
25
+ <li><%= link_to "Sign in", signin_path %></li>
26
+ <% end %>
27
+ </ul>
28
+ </nav>
29
+ </div>
30
+ </div>
31
+ </header>
@@ -0,0 +1,3 @@
1
+ <!--[if lt IE 9]>
2
+ <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
3
+ <![endif]-->
@@ -0,0 +1,22 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title><%= full_title(yield(:title)) %></title>
5
+ <%= stylesheet_link_tag "application", media: "all",
6
+ "data-turbolinks-track" => true %>
7
+ <%= javascript_include_tag "application", "data-turbolinks-track" => true %>
8
+ <%= csrf_meta_tags %>
9
+ <%= render 'layouts/shim' %>
10
+ </head>
11
+ <body>
12
+ <%= render 'layouts/header' %>
13
+ <div class="container">
14
+ <% flash.each do |key, value| %>
15
+ <div class="alert alert-<%= key %>"><%= value %></div>
16
+ <% end %>
17
+ <%= yield %>
18
+ <%= render 'layouts/footer' %>
19
+ <%= debug(params) if Rails.env.development? %>
20
+ </div>
21
+ </body>
22
+ </html>