Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
88 commits
Select commit Hold shift + click to select a range
a33b890
update settings for tests, need to uncomment something
chrislsavage Dec 31, 2015
b45b7d2
beginning model and migrations complete
chrislsavage Dec 31, 2015
d294cde
add trello link
chrislsavage Dec 31, 2015
d95ae60
add user controller
chrislsavage Dec 31, 2015
47a02dc
Merge pull request #1 from nyc-copperheads-2016/add_user_controller
chrislsavage Dec 31, 2015
ba1164a
add gems for testing, add votes controller
chrislsavage Jan 1, 2016
feeb1f8
update database files and add formatting to rspec
chrislsavage Jan 1, 2016
d3d5e48
Add tests for user
chrislsavage Jan 1, 2016
06bab42
Merge pull request #2 from nyc-copperheads-2016/add_gemfile
chrislsavage Jan 1, 2016
a5d7a89
Merge pull request #3 from nyc-copperheads-2016/setup
chrislsavage Jan 1, 2016
1152909
Merge pull request #4 from nyc-copperheads-2016/user_model_tests
chrislsavage Jan 1, 2016
f20d882
Add Questions Show page
Jan 2, 2016
56866ea
Merge pull request #5 from nyc-copperheads-2016/question_show
dfroberts2 Jan 2, 2016
5d38e0a
add user create function
Jan 2, 2016
5c269c6
Merge pull request #6 from nyc-copperheads-2016/add_user_capabilities
chrislsavage Jan 2, 2016
f1ad791
Provide question.id to question_path
Jan 2, 2016
5a08341
Merge pull request #7 from nyc-copperheads-2016/question_show
dfroberts2 Jan 2, 2016
74e4a07
add schema pictures
chrislsavage Jan 2, 2016
28d3e63
Merge pull request #8 from nyc-copperheads-2016/pictures
chrislsavage Jan 2, 2016
2bfb61a
Complete Sessions Controller; Allow User To See If They Logged In/Log…
Jan 2, 2016
600e6fd
Merge pull request #9 from nyc-copperheads-2016/add_user_login
chrislsavage Jan 2, 2016
5d66116
add seed file
chrislsavage Jan 2, 2016
0c73266
Merge pull request #10 from nyc-copperheads-2016/seed
dfroberts2 Jan 2, 2016
39211db
Fix sessions route bug
Jan 2, 2016
78522e3
Add questions form and create
Jan 2, 2016
6d0bba3
Merge pull request #11 from nyc-copperheads-2016/questions_new
dfroberts2 Jan 2, 2016
b6fe8ca
Make questions association with current_user
Jan 2, 2016
b537b00
Merge pull request #12 from nyc-copperheads-2016/questions_new
dfroberts2 Jan 2, 2016
82dabb2
add seed
chrislsavage Jan 2, 2016
1b8649b
Change Password Settings To Reflect Password/Username Constraints
Jan 2, 2016
2ac1bff
seed file change
chrislsavage Jan 2, 2016
0b00192
Merge pull request #13 from nyc-copperheads-2016/seed
dfroberts2 Jan 2, 2016
6bb3b1d
Create comment partial form and add comments controller
Jan 3, 2016
23b42c4
add accepted answer migrations
Jan 3, 2016
60fa66f
add votes routes
Jan 3, 2016
a2fb405
Merge pull request #14 from nyc-copperheads-2016/comments_partial
dfroberts2 Jan 3, 2016
015451c
Merge pull request #15 from nyc-copperheads-2016/questions_migration
dfroberts2 Jan 3, 2016
cfbbd65
Merge pull request #16 from nyc-copperheads-2016/votes
dfroberts2 Jan 3, 2016
6136a7b
Create post answers capability for logged in user
Jan 3, 2016
e9262f6
Merge pull request #17 from nyc-copperheads-2016/post_an_answer_to_qu…
chrislsavage Jan 3, 2016
d7b4974
make answer and question logic in the models
Jan 3, 2016
11a16b6
Merge pull request #18 from nyc-copperheads-2016/question_logic
dfroberts2 Jan 3, 2016
44f15dd
Add voting logic
Jan 3, 2016
bb31b04
Merge pull request #19 from nyc-copperheads-2016/voting_logic
dfroberts2 Jan 3, 2016
1ccfb90
Change comments and questions controllers to allow comments to be pos…
Jan 3, 2016
3c32073
Merge pull request #20 from nyc-copperheads-2016/add_comments_to_answ…
aattsai Jan 3, 2016
5fdab53
add vote capability to questions
Jan 3, 2016
ed223c7
fix migration for votes author_id column, add rspec
chrislsavage Jan 3, 2016
920754b
Merge pull request #22 from nyc-copperheads-2016/add_votes_rpsec
aattsai Jan 3, 2016
88af863
Merge pull request #21 from nyc-copperheads-2016/add_votes
aattsai Jan 3, 2016
9bb84db
Add answer spec without any method tests
chrislsavage Jan 3, 2016
16cfd52
Update user spec to fix password failures
chrislsavage Jan 3, 2016
b102add
Merge pull request #23 from nyc-copperheads-2016/user_answer_spec
dfroberts2 Jan 3, 2016
e71cdfa
Add votes for answers and comments
Jan 3, 2016
8cfb718
Merge pull request #24 from nyc-copperheads-2016/add_votes
aquarian5 Jan 3, 2016
415dde9
add factory fille
chrislsavage Jan 3, 2016
41660e9
Add favorite answer picking ability
Jan 3, 2016
cce89c7
Add login first capability
Jan 3, 2016
9631759
Merge pull request #25 from nyc-copperheads-2016/add_favorite_answer
aattsai Jan 3, 2016
a326baa
Implement and display author total points
Jan 3, 2016
6078a1f
Merge pull request #26 from nyc-copperheads-2016/add_total_point_for_…
dfroberts2 Jan 3, 2016
09d4af0
vote logic
chrislsavage Jan 3, 2016
cb95a26
fix conflicts
chrislsavage Jan 3, 2016
ddce454
Merge pull request #27 from nyc-copperheads-2016/logic
dfroberts2 Jan 3, 2016
1a928e4
update question and answr logic
chrislsavage Jan 3, 2016
d3f9b8d
Merge pull request #28 from nyc-copperheads-2016/logic
dfroberts2 Jan 3, 2016
c8c01d5
add feature to sort answer order by selected answer, then by top vote…
Jan 3, 2016
5cea91f
Merge pull request #29 from nyc-copperheads-2016/sort_answer_order
chrislsavage Jan 3, 2016
84635c9
questions toggle
chrislsavage Jan 3, 2016
bc905f0
Merge pull request #30 from nyc-copperheads-2016/logic
dfroberts2 Jan 4, 2016
7fc3071
fix logic for top voted questions sorting
Jan 4, 2016
411071d
Merge pull request #31 from nyc-copperheads-2016/top_voted_questions
chrislsavage Jan 4, 2016
50b5640
implement css in to master branch
Jan 4, 2016
b96e66e
fix logic
chrislsavage Jan 4, 2016
433a350
update logic
chrislsavage Jan 4, 2016
904da2e
add link to home page
chrislsavage Jan 4, 2016
b773e93
Merge pull request #34 from nyc-copperheads-2016/add_home_page_link
chrislsavage Jan 4, 2016
ada8a90
move byebug
chrislsavage Jan 4, 2016
d76e576
move byebug
chrislsavage Jan 4, 2016
88ea29a
move byebug
chrislsavage Jan 4, 2016
3e87a0b
Merge pull request #35 from nyc-copperheads-2016/bybug
chrislsavage Jan 4, 2016
4869b32
move byebug
chrislsavage Jan 4, 2016
ea810d1
Merge pull request #36 from nyc-copperheads-2016/bybug
chrislsavage Jan 4, 2016
2a3d16e
move byebug
chrislsavage Jan 4, 2016
b49f3c2
Merge pull request #37 from nyc-copperheads-2016/bybug
chrislsavage Jan 4, 2016
6ff2480
done
chrislsavage Jan 4, 2016
46e1114
Merge pull request #38 from nyc-copperheads-2016/bybug
chrislsavage Jan 4, 2016
8d2ac66
Remove tmp files from git
stevecass Jan 5, 2016
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .byebug_history
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
exit
Question.questions_sorted_by_most_votes

3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
bin/rspec
coverage/
log/test.log
3 changes: 3 additions & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
--color
--require spec_helper
--format documentation
10 changes: 6 additions & 4 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
source 'https://rubygems.org'

ruby '2.2.3'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.5'
Expand Down Expand Up @@ -32,19 +32,21 @@ gem 'bcrypt', '~> 3.1.7'

group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug'
gem 'rails_12factor'
gem 'rspec-rails'
gem 'simplecov', :require => false, :group => :test
gem 'shoulda-matchers', '~> 3.0'
gem 'factory_girl_rails'
end

group :development do
# Access an IRB console on exception pages or by using <%= console %> in views
gem 'web-console', '~> 2.0'
gem 'faker'
gem 'factory_girl_rails'

gem 'capybara'
gem 'database_cleaner'
gem 'launchy'
gem 'selenium-webdriver'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
end
Expand Down
28 changes: 26 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,22 @@ GEM
minitest (~> 5.1)
thread_safe (~> 0.3, >= 0.3.4)
tzinfo (~> 1.1)
addressable (2.4.0)
arel (6.0.3)
bcrypt (3.1.10)
binding_of_caller (0.7.2)
debug_inspector (>= 0.0.1)
builder (3.2.2)
byebug (8.2.1)
capybara (2.5.0)
mime-types (>= 1.16)
nokogiri (>= 1.3.3)
rack (>= 1.0.0)
rack-test (>= 0.5.4)
xpath (~> 2.0)
childprocess (0.5.8)
ffi (~> 1.0, >= 1.0.11)
concurrent-ruby (1.0.0)
database_cleaner (1.5.1)
debug_inspector (0.0.2)
diff-lcs (1.2.5)
docile (1.1.5)
Expand All @@ -55,6 +64,7 @@ GEM
railties (>= 3.0.0)
faker (1.6.1)
i18n (~> 0.5)
ffi (1.9.10)
globalid (0.3.6)
activesupport (>= 4.1.0)
i18n (0.7.0)
Expand All @@ -66,6 +76,8 @@ GEM
railties (>= 4.2.0)
thor (>= 0.14, < 2.0)
json (1.8.3)
launchy (2.4.3)
addressable (~> 2.3)
loofah (2.0.3)
nokogiri (>= 1.5.9)
mail (2.6.3)
Expand Down Expand Up @@ -129,6 +141,7 @@ GEM
rspec-mocks (~> 3.4.0)
rspec-support (~> 3.4.0)
rspec-support (3.4.1)
rubyzip (1.1.7)
sass (3.4.20)
sass-rails (5.0.4)
railties (>= 4.0.0, < 5.0)
Expand All @@ -139,6 +152,11 @@ GEM
sdoc (0.4.1)
json (~> 1.7, >= 1.7.7)
rdoc (~> 4.0)
selenium-webdriver (2.48.1)
childprocess (~> 0.5)
multi_json (~> 1.0)
rubyzip (~> 1.0)
websocket (~> 1.0)
shoulda-matchers (3.0.1)
activesupport (>= 4.0.0)
simplecov (0.11.1)
Expand Down Expand Up @@ -167,23 +185,29 @@ GEM
binding_of_caller (>= 0.7.2)
railties (>= 4.0)
sprockets-rails (>= 2.0, < 4.0)
websocket (1.2.2)
xpath (2.0.0)
nokogiri (~> 1.3)

PLATFORMS
ruby

DEPENDENCIES
bcrypt (~> 3.1.7)
byebug
capybara
database_cleaner
factory_girl_rails
faker
jbuilder (~> 2.0)
jquery-rails
launchy
pg (~> 0.15)
rails (= 4.2.5)
rails_12factor
rspec-rails
sass-rails (~> 5.0)
sdoc (~> 0.4.0)
selenium-webdriver
shoulda-matchers (~> 3.0)
simplecov
spring
Expand Down
Binary file added IMG_2113.JPG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added IMG_2114.JPG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions README.rdoc
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
== README


Trello:

https://trello.com/b/xtk06JMI/overflow

This README would normally document whatever steps are necessary to get the
application up and running.

Expand Down
53 changes: 53 additions & 0 deletions app/assets/stylesheets/site_css.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@

body {
background-color: #eeeeee;
font-family: "HelveticaNeue-Light", "Helvetica Neue Light", "Helvetica Neue", Helvetica, Arial, "Lucida Grande", sans-serif;
font-weight: 500;
font-size: 14px;
color: #1e1e1e;
}

h1 {
font-family: Georgia, serif;
font-style: italic;
color: #BA55D3;
}

h2 {
font-family: Georgia, serif;
font-style: italic;
color: #BA55D3;
}

nav {
background-color: #004060;
color: #ffffff;
padding: 4px 8px;
}

li {
color: #BA55D3 ;
}

p3 {
font-style: italic;
color: #008000;
}

p2 {
font-style: italic;
color: #DC143C;
}

.question_header {
border: dotted black 2px ;
}

.answer_header {
margin-left: 5%;
font-size: 1.5em;
}

.comments {
margin-left: 5%;
}
20 changes: 20 additions & 0 deletions app/controllers/answers_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
class AnswersController < ApplicationController
before_action :ensure_logged_in, only:[:create]
def create
question = Question.find_by(id: params[:question_id])
@answer = current_user.answers.build(answer_params)
@answer.question = question
if @answer.save
redirect_to question_path(question.id)
else
flash[:notice] = "Something went wrong."
redirect_to question_path(question.id)
end
end

def answer_params
params.require(:answer).permit(:body)
end
end


13 changes: 13 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,17 @@ class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
helper_method :current_user, :logged_in?

def current_user
@current_user ||= User.find_by(id: session[:user_id])
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be better to add if session[:user_id] to the end of this to avoid running the query when we know the session[:user_id] is nil.

end

def logged_in?
!!session[:user_id]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would do !!current_user to ensure that session_id maps to a valid user

end

def ensure_logged_in
redirect_to login_path unless current_user
end
end
36 changes: 36 additions & 0 deletions app/controllers/comments_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
class CommentsController < ApplicationController
before_action :ensure_logged_in, only:[:create]
def new
@comment = Comment.new
end

def create
if (params.has_key?(:answer_id))
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If your routes are nested a trick like the following can be helpful to avoid a bunch of if / elseif stuff.

private
  def load_voteable
    resource, id = request.path.split('/')[1, 2]
    @voteable = resource.singularize.classify.constantize.find(id)
  end

@answer = Answer.find_by(id: params[:answer_id])
comment = current_user.comments.build(comment_params)
comment.commentable_id = params[:answer_id]
comment.commentable_type = "Answer"
params[:question_id] = @answer.question.id
else
comment = current_user.comments.build(comment_params)
comment.commentable_type = "Question"
comment.commentable_id = params[:question_id]
end

if comment.save
redirect_to question_path(params[:question_id]) #have to pass in question.id as a local in the question show page when the comment is to an answer
else
render 'new'
end
end

private

def comment_params
params.require(:comment).permit(:body)
end

end



52 changes: 52 additions & 0 deletions app/controllers/questions_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
class QuestionsController < ApplicationController
before_action :ensure_logged_in, only:[:new, :create, :update]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd be tempted to move this to ApplicationController and use skip_before_action in the (few) controllers you don't want it to apply

def index
@questions = Question.all
end

def trending
@questions = Question.trending_questions
render 'index'
end

def voted
@questions = Question.top_voted_questions
render 'index'
end

def new
@question = Question.new
end

def create
question = current_user.questions.build(question_params)
if question.save
redirect_to root_path
else
render 'new'
end
end

def show
@question = Question.find(params[:id])
@answers = Answer.top_voted_answer(@question)
@answer = Answer.new
@comment = Comment.new
@vote = Vote.new
end

def update
question = Question.find(params[:id])
question.update_attributes(accepted_answer_id: params[:chosen_answer_id])
redirect_to question_path(question)
end



private

def question_params
params.require(:question).permit(:title, :body)
end

end
25 changes: 25 additions & 0 deletions app/controllers/sessions_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
class SessionsController < ApplicationController
skip_before_action :ensure_logged_in
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The way things are now this is unnecessary


def new
end

def create
user = User.find_by(username: params[:username])
if user && user.authenticate(params[:password])
flash[:notice] = 'Welcome to our site!'
session[:user_id] = user.id
redirect_to root_path
else
flash.now[:warning] = 'Login failed. Please Try Again.'
render :new
end
end

def destroy
session.clear
flash[:notice] = 'Thanks For Visiting The Site! Please Return Soon!'
redirect_to root_path
end

end
26 changes: 26 additions & 0 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
class UsersController < ApplicationController
def new
@user = User.new
end

def create
@user = User.new(user_params)
if @user.save
session[:user_id] = @user.id
flash[:notice] = 'Congratulations! You Are Now Registered!'
redirect_to root_path
else
render :new
end
end

def edit
end

def destroy
end

def user_params
params.require(:user).permit(:username, :password, :password_confirmation)
end
end
Loading