Skip to content

Commit 64c67d7

Browse files
committed
Adding fields to the User model
1 parent c45108d commit 64c67d7

File tree

9 files changed

+177
-30
lines changed

9 files changed

+177
-30
lines changed

Gemfile

+7
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,18 @@ gem 'devise'
1818
gem 'rails_admin'
1919
gem 'slim'
2020
gem 'nokogiri'
21+
gem "mongoid-paperclip", :require => "mongoid_paperclip"
22+
gem 'aws-sdk', '~> 1.3.4'
2123

2224
# Group Gems
2325
group :doc do
2426
gem 'sdoc', '~> 0.4.0'
2527
end
2628

29+
group :development do
30+
gem 'guard-rspec', require: false
31+
end
32+
2733
group :test, :development do
2834
gem 'rspec-rails'
2935
gem 'factory_girl_rails'
@@ -35,6 +41,7 @@ group :test, :development do
3541
gem 'simplecov'
3642
gem 'pry'
3743
gem 'rails-pry'
44+
gem 'shoulda-matchers'
3845
end
3946

4047
gem "codeclimate-test-reporter", group: :test, require: nil

Gemfile.lock

+51
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ GEM
2828
thread_safe (~> 0.1)
2929
tzinfo (~> 1.1)
3030
arel (5.0.1.20140414130214)
31+
aws-sdk (1.3.9)
32+
httparty (~> 0.7)
33+
json (~> 1.4)
34+
nokogiri (>= 1.4.4)
35+
uuidtools (~> 2.1)
3136
bcrypt (3.1.7)
3237
better_errors (1.1.0)
3338
coderay (>= 1.0.0)
@@ -45,6 +50,12 @@ GEM
4550
capybara-webkit (1.1.0)
4651
capybara (~> 2.0, >= 2.0.2)
4752
json
53+
celluloid (0.16.0)
54+
timers (~> 4.0.0)
55+
climate_control (0.0.3)
56+
activesupport (>= 3.0)
57+
cocaine (0.5.4)
58+
climate_control (>= 0.0.3, < 1.0)
4859
codeclimate-test-reporter (0.4.0)
4960
simplecov (>= 0.7.1, < 1.0.0)
5061
coderay (1.1.0)
@@ -75,11 +86,26 @@ GEM
7586
factory_girl_rails (4.4.1)
7687
factory_girl (~> 4.4.0)
7788
railties (>= 3.0.0)
89+
ffi (1.9.6)
7890
font-awesome-rails (4.1.0.0)
7991
railties (>= 3.2, < 5.0)
92+
formatador (0.2.5)
93+
guard (2.7.0)
94+
formatador (>= 0.2.4)
95+
listen (~> 2.7)
96+
lumberjack (~> 1.0)
97+
pry (>= 0.9.12)
98+
thor (>= 0.18.1)
99+
guard-rspec (4.3.1)
100+
guard (~> 2.1)
101+
rspec (>= 2.14, < 4.0)
80102
haml (4.0.5)
81103
tilt
82104
hike (1.2.3)
105+
hitimes (1.2.2)
106+
httparty (0.13.1)
107+
json (~> 1.8)
108+
multi_xml (>= 0.5.2)
83109
i18n (0.6.11)
84110
jbuilder (2.1.3)
85111
activesupport (>= 3.0.0, < 5)
@@ -94,6 +120,11 @@ GEM
94120
actionpack (>= 3.0.0)
95121
activesupport (>= 3.0.0)
96122
kgio (2.9.2)
123+
listen (2.7.11)
124+
celluloid (>= 0.15.2)
125+
rb-fsevent (>= 0.9.3)
126+
rb-inotify (>= 0.9)
127+
lumberjack (1.0.9)
97128
mail (2.5.4)
98129
mime-types (~> 1.16)
99130
treetop (~> 1.4.8)
@@ -106,6 +137,8 @@ GEM
106137
moped (~> 2.0.0)
107138
origin (~> 2.1)
108139
tzinfo (>= 0.3.37)
140+
mongoid-paperclip (0.0.9)
141+
paperclip (>= 2.3.6)
109142
mongoid-rspec (1.10.0)
110143
mongoid (>= 3.0.1)
111144
rake
@@ -115,12 +148,18 @@ GEM
115148
connection_pool (~> 2.0)
116149
optionable (~> 0.2.0)
117150
multi_json (1.10.1)
151+
multi_xml (0.5.5)
118152
nested_form (0.3.2)
119153
nokogiri (1.6.3.1)
120154
mini_portile (= 0.6.0)
121155
optionable (0.2.0)
122156
origin (2.1.1)
123157
orm_adapter (0.5.0)
158+
paperclip (4.2.0)
159+
activemodel (>= 3.0.0)
160+
activesupport (>= 3.0.0)
161+
cocaine (~> 0.5.3)
162+
mime-types
124163
polyglot (0.3.5)
125164
pry (0.10.0)
126165
coderay (~> 1.1.0)
@@ -169,6 +208,9 @@ GEM
169208
thor (>= 0.18.1, < 2.0)
170209
raindrops (0.13.0)
171210
rake (10.3.2)
211+
rb-fsevent (0.9.4)
212+
rb-inotify (0.9.5)
213+
ffi (>= 0.5.0)
172214
rdoc (4.1.1)
173215
json (~> 1.4)
174216
remotipart (1.2.1)
@@ -202,6 +244,8 @@ GEM
202244
sdoc (0.4.0)
203245
json (~> 1.8)
204246
rdoc (~> 4.0, < 5.0)
247+
shoulda-matchers (2.7.0)
248+
activesupport (>= 3.0.0)
205249
simplecov (0.9.0)
206250
docile (~> 1.1.0)
207251
multi_json
@@ -228,6 +272,8 @@ GEM
228272
thor (0.19.1)
229273
thread_safe (0.3.4)
230274
tilt (1.4.1)
275+
timers (4.0.1)
276+
hitimes
231277
treetop (1.4.15)
232278
polyglot
233279
polyglot (>= 0.3.1)
@@ -242,6 +288,7 @@ GEM
242288
kgio (~> 2.6)
243289
rack
244290
raindrops (~> 0.7)
291+
uuidtools (2.1.5)
245292
warden (1.2.3)
246293
rack (>= 1.0)
247294
xpath (2.0.0)
@@ -251,6 +298,7 @@ PLATFORMS
251298
ruby
252299

253300
DEPENDENCIES
301+
aws-sdk (~> 1.3.4)
254302
better_errors
255303
binding_of_caller
256304
capybara
@@ -260,9 +308,11 @@ DEPENDENCIES
260308
database_cleaner
261309
devise
262310
factory_girl_rails
311+
guard-rspec
263312
jbuilder (~> 2.0)
264313
jquery-rails
265314
mongoid
315+
mongoid-paperclip
266316
mongoid-rspec
267317
nokogiri
268318
pry
@@ -273,6 +323,7 @@ DEPENDENCIES
273323
rspec-rails
274324
sass-rails (~> 4.0.3)
275325
sdoc (~> 0.4.0)
326+
shoulda-matchers
276327
simplecov
277328
slim
278329
thin

Guardfile

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# A sample Guardfile
2+
# More info at https://github.com/guard/guard#readme
3+
4+
# Note: The cmd option is now required due to the increasing number of ways
5+
# rspec may be run, below are examples of the most common uses.
6+
# * bundler: 'bundle exec rspec'
7+
# * bundler binstubs: 'bin/rspec'
8+
# * spring: 'bin/rsspec' (This will use spring if running and you have
9+
# installed the spring binstubs per the docs)
10+
# * zeus: 'zeus rspec' (requires the server to be started separetly)
11+
# * 'just' rspec: 'rspec'
12+
guard :rspec, cmd: 'bundle exec rspec' do
13+
watch(%r{^spec/.+_spec\.rb$})
14+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
15+
watch('spec/spec_helper.rb') { "spec" }
16+
17+
# Rails example
18+
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
19+
watch(%r{^app/(.*)(\.erb|\.haml|\.slim)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
20+
watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
21+
watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
22+
watch('config/routes.rb') { "spec/routing" }
23+
watch('app/controllers/application_controller.rb') { "spec/controllers" }
24+
watch('spec/rails_helper.rb') { "spec" }
25+
26+
# Capybara features specs
27+
watch(%r{^app/views/(.+)/.*\.(erb|haml|slim)$}) { |m| "spec/features/#{m[1]}_spec.rb" }
28+
29+
# Turnip features and steps
30+
watch(%r{^spec/acceptance/(.+)\.feature$})
31+
watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
32+
end
33+

app/models/concerns/user_devise.rb

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
module UserDevise
2+
extend ActiveSupport::Concern
3+
4+
included do
5+
devise :database_authenticatable, :recoverable, :rememberable, :trackable,
6+
:validatable
7+
8+
## Database authenticatable
9+
field :email, type: String, default: ""
10+
field :encrypted_password, type: String, default: ""
11+
12+
## Recoverable
13+
field :reset_password_token, type: String
14+
field :reset_password_sent_at, type: Time
15+
16+
## Rememberable
17+
field :remember_created_at, type: Time
18+
19+
## Trackable
20+
field :sign_in_count, type: Integer, default: 0
21+
field :current_sign_in_at, type: Time
22+
field :last_sign_in_at, type: Time
23+
field :current_sign_in_ip, type: String
24+
field :last_sign_in_ip, type: String
25+
26+
end
27+
end

app/models/user.rb

+15-30
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,21 @@
11
class User
22
include Mongoid::Document
3-
# Include default devise modules. Others available are:
4-
# :confirmable, :lockable, :timeoutable and :omniauthable
5-
devise :database_authenticatable, :recoverable, :rememberable, :trackable,
6-
:validatable
3+
include Mongoid::Paperclip
4+
include UserDevise # See this concern file for devise related fields
5+
has_mongoid_attached_file :profile_image
76

8-
## Database authenticatable
9-
field :email, type: String, default: ""
10-
field :encrypted_password, type: String, default: ""
7+
%i( first_name
8+
last_name
9+
biography
10+
address_line_1
11+
address_line_2
12+
postal_code
13+
state_province
14+
country
15+
primary_phone ).each do |string_field|
16+
field string_field
17+
end
1118

12-
## Recoverable
13-
field :reset_password_token, type: String
14-
field :reset_password_sent_at, type: Time
19+
validates :first_name, :last_name, :email, presence: true
1520

16-
## Rememberable
17-
field :remember_created_at, type: Time
18-
19-
## Trackable
20-
field :sign_in_count, type: Integer, default: 0
21-
field :current_sign_in_at, type: Time
22-
field :last_sign_in_at, type: Time
23-
field :current_sign_in_ip, type: String
24-
field :last_sign_in_ip, type: String
25-
26-
## Confirmable
27-
# field :confirmation_token, type: String
28-
# field :confirmed_at, type: Time
29-
# field :confirmation_sent_at, type: Time
30-
# field :unconfirmed_email, type: String # Only if using reconfirmable
31-
32-
## Lockable
33-
# field :failed_attempts, type: Integer, default: 0 # Only if lock strategy is :failed_attempts
34-
# field :unlock_token, type: String # Only if unlock strategy is :email or :both
35-
# field :locked_at, type: Time
3621
end

config/environments/development.rb

+11
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,15 @@
3333

3434
# Raises error for missing translations
3535
# config.action_view.raise_on_missing_translations = true
36+
37+
config.paperclip_defaults =
38+
{
39+
storage: :fog,
40+
fog_credentials: {
41+
provider: "Local",
42+
local_root: "#{Rails.root}/public"
43+
},
44+
fog_directory: 'user_profiles',
45+
fog_host: "localhost"
46+
}
3647
end

config/environments/production.rb

+15
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,19 @@
7878

7979
# Use default logging formatter so that PID and timestamp are not suppressed.
8080
config.log_formatter = ::Logger::Formatter.new
81+
82+
config.paperclip_defaults =
83+
{
84+
storage: :fog,
85+
fog_credentials: {
86+
aws_access_key_id: '<your aws_access_key_id>'
87+
aws_secret_access_key: '<your aws_secret_access_key>'
88+
provider: 'AWS'
89+
region: 'eu-west-1'
90+
scheme: 'https'
91+
},
92+
fog_directory: 'user_profiles',
93+
fog_host: ""
94+
}
95+
8196
end

config/environments/test.rb

+11
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,15 @@
3636

3737
# Raises error for missing translations
3838
# config.action_view.raise_on_missing_translations = true
39+
40+
config.paperclip_defaults =
41+
{
42+
storage: :fog,
43+
fog_credentials: {
44+
provider: "Local",
45+
local_root: "#{Rails.root}/public"
46+
},
47+
fog_directory: 'user_profiles',
48+
fog_host: "localhost"
49+
}
3950
end

spec/models/user_spec.rb

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
require 'rails_helper'
2+
3+
describe User do
4+
%i(first_name last_name email).each do |attr|
5+
it { should validate_presence_of(attr)}
6+
end
7+
end

0 commit comments

Comments
 (0)