Skip to content

Commit ff5dce3

Browse files
author
Hoa Nguyen & Hoa Nguyen
committed
Conflicts: app/controllers/comments_controller.rb app/views/comments/new.html.erb app/views/questions/show.html.erb
2 parents 7742d7c + 59b18cb commit ff5dce3

19 files changed

+292
-50
lines changed

Gemfile

+10-1
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,23 @@ gem 'sdoc', '~> 0.4.0', group: :doc
2828

2929
# Use Unicorn as the app server
3030
# gem 'unicorn'
31+
group :test, :development do
32+
gem "rspec-rails", "~> 2.0"
33+
end
34+
3135

3236
# Use Capistrano for deployment
3337
# gem 'capistrano-rails', group: :development
3438

3539
group :development, :test do
3640
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
41+
gem 'shoulda-matchers'
3742
gem 'byebug'
38-
43+
gem 'factory_girl_rails'
44+
gem 'faker'
45+
gem 'capybara'
46+
gem 'launchy'
47+
gem 'database_cleaner'
3948
# Access an IRB console on exception pages or by using <%= console %> in views
4049
gem 'web-console', '~> 2.0'
4150

Gemfile.lock

+44
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,20 @@ GEM
3636
minitest (~> 5.1)
3737
thread_safe (~> 0.3, >= 0.3.4)
3838
tzinfo (~> 1.1)
39+
addressable (2.3.8)
3940
arel (6.0.0)
4041
bcrypt (3.1.10)
4142
binding_of_caller (0.7.2)
4243
debug_inspector (>= 0.0.1)
4344
builder (3.2.2)
4445
byebug (4.0.5)
4546
columnize (= 0.9.0)
47+
capybara (2.4.4)
48+
mime-types (>= 1.16)
49+
nokogiri (>= 1.3.3)
50+
rack (>= 1.0.0)
51+
rack-test (>= 0.5.4)
52+
xpath (~> 2.0)
4653
coffee-rails (4.1.0)
4754
coffee-script (>= 2.2.0)
4855
railties (>= 4.0.0, < 5.0)
@@ -51,9 +58,18 @@ GEM
5158
execjs
5259
coffee-script-source (1.9.1)
5360
columnize (0.9.0)
61+
database_cleaner (1.4.1)
5462
debug_inspector (0.0.2)
63+
diff-lcs (1.2.5)
5564
erubis (2.7.0)
5665
execjs (2.5.2)
66+
factory_girl (4.5.0)
67+
activesupport (>= 3.0.0)
68+
factory_girl_rails (4.5.0)
69+
factory_girl (~> 4.5.0)
70+
railties (>= 3.0.0)
71+
faker (1.4.3)
72+
i18n (~> 0.5)
5773
globalid (0.3.5)
5874
activesupport (>= 4.1.0)
5975
hike (1.2.3)
@@ -66,6 +82,8 @@ GEM
6682
railties (>= 4.2.0)
6783
thor (>= 0.14, < 2.0)
6884
json (1.8.2)
85+
launchy (2.4.3)
86+
addressable (~> 2.3)
6987
loofah (2.0.1)
7088
nokogiri (>= 1.5.9)
7189
mail (2.6.3)
@@ -107,6 +125,21 @@ GEM
107125
rake (10.4.2)
108126
rdoc (4.2.0)
109127
json (~> 1.4)
128+
rspec-collection_matchers (1.1.2)
129+
rspec-expectations (>= 2.99.0.beta1)
130+
rspec-core (2.99.2)
131+
rspec-expectations (2.99.2)
132+
diff-lcs (>= 1.1.3, < 2.0)
133+
rspec-mocks (2.99.3)
134+
rspec-rails (2.99.0)
135+
actionpack (>= 3.0)
136+
activemodel (>= 3.0)
137+
activesupport (>= 3.0)
138+
railties (>= 3.0)
139+
rspec-collection_matchers
140+
rspec-core (~> 2.99.0)
141+
rspec-expectations (~> 2.99.0)
142+
rspec-mocks (~> 2.99.0)
110143
sass (3.4.13)
111144
sass-rails (5.0.3)
112145
railties (>= 4.0.0, < 5.0)
@@ -117,6 +150,8 @@ GEM
117150
sdoc (0.4.1)
118151
json (~> 1.7, >= 1.7.7)
119152
rdoc (~> 4.0)
153+
shoulda-matchers (2.8.0)
154+
activesupport (>= 3.0.0)
120155
spring (1.3.4)
121156
sprockets (2.12.3)
122157
hike (~> 1.2)
@@ -142,20 +177,29 @@ GEM
142177
binding_of_caller (>= 0.7.2)
143178
railties (>= 4.0)
144179
sprockets-rails (>= 2.0, < 4.0)
180+
xpath (2.0.0)
181+
nokogiri (~> 1.3)
145182

146183
PLATFORMS
147184
ruby
148185

149186
DEPENDENCIES
150187
bcrypt (~> 3.1.7)
151188
byebug
189+
capybara
152190
coffee-rails (~> 4.1.0)
191+
database_cleaner
192+
factory_girl_rails
193+
faker
153194
jbuilder (~> 2.0)
154195
jquery-rails
196+
launchy
155197
pg
156198
rails (= 4.2.1)
199+
rspec-rails (~> 2.0)
157200
sass-rails (~> 5.0)
158201
sdoc (~> 0.4.0)
202+
shoulda-matchers
159203
spring
160204
turbolinks
161205
uglifier (>= 1.3.0)

app/assets/stylesheets/application.css

+75-14
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ ul li {
109109
width: 17em;
110110
}
111111

112-
/*Questions Index*/
112+
/*Questions Index************************************** */
113113

114114
#all_questions {
115115
margin-top: 3em;
@@ -123,6 +123,7 @@ ul li {
123123

124124
.ind_ques_contents {
125125
margin-left: 6em;
126+
list-style-type: none;
126127
}
127128

128129
.ui_avatar_question {
@@ -134,24 +135,28 @@ ul li {
134135
}
135136

136137
div div p {
137-
color: #0c65a5;
138+
color: #0c65a5 !important;
138139
font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif;
139140
}
140141

141142
div div p:nth-child(2) {
142-
font-size: .7em;
143-
color: #444;
143+
font-size: .8em;
144+
color: #444 !important;
144145
}
145146

146147
div div p:nth-child(4) {
147148
font-size: .7em;
148149
position: absolute;
149150
margin-left: 4.5em;
150151
margin-top: -5.5em;
151-
mar
152152
}
153153

154-
/* question show */
154+
.qi_link {
155+
text-decoration: none !important;
156+
color: #0c65a5 !important;
157+
}
158+
159+
/* question show ********************************* */
155160

156161
.avy {
157162
width: 2em;
@@ -166,7 +171,6 @@ div div p:nth-child(4) {
166171

167172
.user_section {
168173
padding: 12px 0 10px 0;
169-
border-bottom: 1px solid #e0e0e0;
170174
border-top: 1px solid #e0e0e0;
171175
margin-left: 1.2em;
172176
font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif;
@@ -180,33 +184,83 @@ div div p:nth-child(4) {
180184
}
181185

182186
#qu_box {
183-
margin-left: 33em;
187+
margin-left: 5em;
188+
margin-top: 2em;
184189
}
185190

186191
.ind_question {
187192
padding: 12px 0 10px 0;
188-
border-bottom: 1px solid #e0e0e0;
189193
border-top: 1px solid #e0e0e0;
190-
margin-left: 1.2em;
194+
margin-left: 5.4em;
191195
font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif;
192196
font-size: .9em;
193197
}
194198

195199
.user {
196-
margin-left: 37em;
200+
margin-top: 2em;
201+
margin-left: .2em;
197202
}
198203

199204
#answer_submit {
200205
margin-top: 2em;
201206
margin-left: 1em;
202207
}
203208

209+
#qs_content{
210+
margin-left: 5em;
211+
}
212+
213+
/* Votes ********************************************************* */
204214

205-
/* User Index/log/signin */
215+
#voting {
216+
margin-top: -4em;
217+
margin-left: 1em;
218+
}
219+
220+
#voting_answer {
221+
margin-left: -4.4em;
222+
position: absolute;
223+
margin-top: -2em;
224+
}
225+
226+
#dislike {
227+
margin-top: .9em;
228+
}
229+
230+
#votes_total {
231+
color: #858D93;
232+
margin-left: .6em;
233+
}
234+
235+
#answer_amount {
236+
font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif;
237+
color: #444;
238+
margin-left: 5em;
239+
margin-bottom: .6em;
240+
}
241+
242+
.arrow-up {
243+
width: 0;
244+
height: 0;
245+
border-left: 15px solid transparent;
246+
border-right: 15px solid transparent;
247+
border-bottom: 15px solid #858D93;
248+
}
249+
250+
.arrow-down {
251+
width: 0;
252+
height: 0;
253+
border-left: 15px solid transparent;
254+
border-right: 15px solid transparent;
255+
border-top: 15px solid #858D93;
256+
}
257+
258+
/* User Index/log/signin****************************** */
206259

207260
#ui_title {
208261
font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif;
209262
margin-left: .7em;
263+
margin-top: 2em;
210264
}
211265

212266
#user_index {
@@ -230,11 +284,12 @@ div div p:nth-child(4) {
230284
}
231285

232286
.user_pro_name {
233-
color: #0c65a5;
287+
color: #0c65a5 !important;
234288
font-size: .8em;
235289
margin-left: 4.5em;
236290
margin-top: 1.2em;
237291
position: absolute;
292+
text-decoration: none !important;
238293
}
239294

240295
.user_pro_location {
@@ -331,7 +386,7 @@ span:hover {
331386
}
332387

333388

334-
/* user show */
389+
/* user show****************************************** */
335390
.user_show {
336391
padding: 12px 0 10px 0;
337392
border-top: 1px solid #e0e0e0;
@@ -364,3 +419,9 @@ span:hover {
364419
position: absolute;
365420
margin-top: .3em;
366421
}
422+
423+
li .new_comment{
424+
color: #888;
425+
opacity: .6;
426+
padding: 0 3px 2px 3px;
427+
}

app/controllers/users_controller.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def new_login
1212
redirect_to questions_path
1313
else
1414
flash.now[:danger] = "Invalid email/password combination"
15-
redirect_to login_path
15+
redirect_to login_users_path
1616
end
1717
end
1818

app/controllers/votes_controller.rb

+26-14
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,33 @@ def create
1111
p "Over Here!!!"
1212
p "#{params[:test]}"
1313
@question = params[:question_id]
14-
15-
if params[:like] == "yes"
16-
@vote = Vote.create!(user_id: session[:user_id], votable_id: params[:question_id], votable_type: "Question" , point: 1)
17-
18-
elsif params[:like] == "no"
19-
@vote = Vote.create!(user_id: session[:user_id], votable_id: params[:question_id], votable_type: "Question", point: -1)
20-
# @question = @vote.question
21-
# if @vote.save!
22-
# redirect_to question_path(@question)
23-
# else
24-
# flash[:notice] = "You can't vote!"
25-
# redirect_to question_path(@question)
26-
# end
14+
@answer = params[:answer_id]
15+
16+
if @question
17+
if params[:like] == "yes"
18+
@vote = Vote.create!(user_id: session[:user_id], votable_id: params[:question_id], votable_type: "Question", point: 1)
19+
elsif params[:like] == "no"
20+
@vote = Vote.create!(user_id: session[:user_id], votable_id: params[:question_id], votable_type: "Question", point: -1)
21+
end
22+
redirect_to question_path(@question)
23+
elsif @answer
24+
if params[:like] == "yes"
25+
@vote = Vote.create!(user_id: session[:user_id], votable_id: params[:answer_id], votable_type: "Answer", point: 1)
26+
elsif params[:like] == "no"
27+
@vote = Vote.create!(user_id: session[:user_id], votable_id: params[:answer_id], votable_type: "Answer", point: -1)
28+
end
29+
the_answer = Answer.find(@answer)
30+
redirect_to question_path(the_answer.question)
2731
end
28-
redirect_to question_path(@question)
2932
end
3033

34+
# if params[:like] == "yes"
35+
# @vote = Vote.create!(user_id: session[:user_id], votable_id: params[:question_id], votable_type: "Question" , point: 1)
36+
37+
# elsif params[:like] == "no"
38+
# @vote = Vote.create!(user_id: session[:user_id], votable_id: params[:question_id], votable_type: "Question", point: -1)
39+
# end
40+
# redirect_to question_path(@question)
41+
# end
42+
3143
end

app/models/user.rb

+7
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@ class User < ActiveRecord::Base
22
has_secure_password
33
has_many :questions, foreign_key: 'creator_id'
44
has_many :answers
5+
validates :email, presence: true
6+
validates :email, format: { with: /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i, on: :create }
57

8+
before_save :rename
9+
10+
def rename
11+
self.name = email.slice(/^(.*?)@/).chop
12+
end
613

714
end

app/views/comments/_comment.html.erb

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<li>
2+
<%= comment.user.username %><BR>
3+
<%= comment.body %>
4+
</li>

0 commit comments

Comments
 (0)