Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge remote-tracking branch 'mleung/master'

  • Loading branch information...
commit bf17251361d8090dc24beacf99e19fb152707fdd 2 parents cd1cec8 + f2e2de8
Hari authored
2  Gemfile
View
@@ -34,7 +34,7 @@ gem 'simple_form', git: "https://github.com/bitzesty/bootstrap_form.git"
gem "semantic_menu", git: "git://github.com/michaek/semantic_menu.git"
gem 'will_paginate' # Pagination
-gem 'rdiscount' # Markdown
+gem 'redcarpet', '~> 3.0' # Markdown
group :development do
# Use unicorn as the web server
7 Gemfile.lock
View
@@ -181,10 +181,9 @@ GEM
thor (~> 0.14.6)
raindrops (0.8.0)
rake (10.1.0)
- rdiscount (1.6.8)
rdoc (3.12.2)
json (~> 1.4)
- redcarpet (2.1.0)
+ redcarpet (3.0.0)
responders (0.6.5)
rest-client (1.6.7)
mime-types (>= 1.16)
@@ -215,7 +214,7 @@ GEM
multi_json (~> 1.0)
simplecov-html (~> 0.7.1)
simplecov-html (0.7.1)
- slop (2.4.3)
+ slop (2.4.4)
sprockets (2.0.4)
hike (~> 1.2)
rack (~> 1.0)
@@ -268,7 +267,7 @@ DEPENDENCIES
pg
pry
rails (= 3.1.11)
- rdiscount
+ redcarpet (~> 3.0)
rspec-rails
sass-rails (~> 3.1.0)
semantic_menu!
2  app/controllers/mailer_controller.rb
View
@@ -1,4 +1,6 @@
class MailerController < ApplicationController
+ load_and_authorize_resource class: Message
+
def new
@users = Array(params[:user])
@emails = User.where(:username => @users).all.map(&:email)
4 app/helpers/application_helper.rb
View
@@ -2,4 +2,8 @@ module ApplicationHelper
def program_path program
"/users/#{program.author_username}/programs/#{program.slug}"
end
+
+ def markdown(text)
+ Redcarpet::Markdown.new(Redcarpet::Render::HTML.new(hard_wrap: true), autolink: true).render(text).html_safe
+ end
end
2  app/models/deleted_user.rb
View
@@ -10,4 +10,4 @@ def email
def to_param
'deleted_user'
end
-end
+end
3  app/views/answers/_list.html.haml
View
@@ -3,8 +3,7 @@
.meta
#{link_to list.user.username, user_path(list.user)} says
.description
- :markdown
- #{list.description}
+ =markdown(list.description)
.links
- if can? :update, list
3  app/views/blog/index.html.haml
View
@@ -13,6 +13,5 @@
= post.created_at.strftime("Posted %B %d, %Y at %l:%M %p")
.content
- :markdown
- #{post.content}
+ =markdown(post.content)
3  app/views/blog/show.html.haml
View
@@ -11,5 +11,4 @@
= @post.created_at.strftime("Posted %B %d, %Y at %l:%M %p")
.content
- :markdown
- #{@post.content}
+ =markdown(@post.content)
3  app/views/lessons/show.html.haml
View
@@ -10,5 +10,4 @@
#lesson-content
= lesson_categories @lesson
- :markdown
- #{@lesson.output}
+ =markdown(@lesson.output)
2  app/views/questions/index.html.haml
View
@@ -26,4 +26,4 @@
%ul.questions
= render :partial => "list", :collection => collection, :as => :question
-= will_paginate
+= will_paginate(@questions, renderer: @support ? PrefixLinkRenderer.new('/support') : nil)
2  app/views/questions/new.html.haml
View
@@ -1,4 +1,4 @@
- content_for :title do
New Question
-= render 'form'
+= render 'form'
3  app/views/questions/show.html.haml
View
@@ -26,8 +26,7 @@
.description
- :markdown
- #{resource.description}
+ =markdown(resource.description)
%h2= pluralize(resource.answers.count, "response")
%ul.answers
2  app/views/static/faq.html.haml
View
@@ -82,4 +82,4 @@
## Thanks!
- Special thanks goes out to Eric Affleck for writing this FAQ.
+ Special thanks goes out to Eric Affleck for writing this FAQ.
13 features/questions_pagination.feature
View
@@ -0,0 +1,13 @@
+Feature: Pagination for different types of questions
+
+ As a user of the site, I can view pages of different types of questions
+
+ Scenario: View support questions
+ Given support questions exist
+ When I visit the support questions page
+ Then I should see a link to the next page of support questions
+
+ Scenario: View non-support questions
+ Given questions exist
+ When I visit the questions page
+ Then I should see a link to the next page of questions
16 features/step_definitions/question_steps.rb
View
@@ -76,3 +76,19 @@ def create_question_for(user)
visit question_path(@question)
page.should_not have_content('Delete')
end
+
+Given /^(\w*)\s?questions exist$/ do |type|
+ 30.times do
+ Question.create(title: 'Test', description: 'Test',
+ support: type == 'support' ? true : false)
+ end
+end
+
+When /^I visit the (\w*)\s?questions page$/ do |type|
+ visit(type == 'support' ? support_questions_path : questions_path)
+end
+
+Then /^I should see a link to the next page of (\w*)\s?questions$/ do |type|
+ href = type == 'support' ? '/support/questions?page=2' : '/questions?page=2'
+ page.should have_link '2', href: href
+end
12 lib/prefix_link_renderer.rb
View
@@ -0,0 +1,12 @@
+class PrefixLinkRenderer < WillPaginate::ActionView::LinkRenderer
+ def initialize(prefix)
+ @prefix = prefix
+ super()
+ end
+
+ protected
+
+ def url(page)
+ @prefix + super
+ end
+end
123 spec/controllers/mailer_controller_spec.rb
View
@@ -3,18 +3,58 @@
describe MailerController do
let(:user) { Fabricate(:user) }
let(:users) { Fabricate.sequence(:user, 5)}
+ let(:diffusion) { Fabricate.build(:diffusion) }
+
+ shared_examples 'unauthorized' do
+ it 'redirects to the login page' do
+ response.should redirect_to(login_path)
+ end
+ end
describe "GET 'new' for a single user email" do
- it "returns http success" do
- get :new, user: Array(user)
- response.should be_success
+
+ context 'when user is a moderator' do
+ before { sign_in Fabricate(:user, moderator: true) }
+ it "returns http success" do
+ get :new, user: Array(user)
+ response.should be_success
+ end
+ end
+
+ context 'when user is not a moderator' do
+ before do
+ sign_in Fabricate(:user)
+ get :new, user: Array(user)
+ end
+ it_behaves_like 'unauthorized'
+ end
+
+ context 'when user is a guest' do
+ before { get :new, user: Array(user) }
+ it_behaves_like 'unauthorized'
end
end
describe "GET 'new' for a diffusion" do
- it "returns http success" do
- get :new, user: Array(users)
- response.should be_success
+ context 'when user is a moderator' do
+ before { sign_in Fabricate(:user, moderator: true) }
+ it "returns http success" do
+ get :new, user: Array(users)
+ response.should be_success
+ end
+ end
+
+ context 'when user is not a moderator' do
+ before do
+ sign_in Fabricate(:user)
+ get :new, user: Array(users)
+ end
+ it_behaves_like 'unauthorized'
+ end
+
+ context 'when user is a guest' do
+ before { get :new, user: Array(users) }
+ it_behaves_like 'unauthorized'
end
end
@@ -23,37 +63,68 @@
@message = Fabricate.build(:message)
end
- it 'delivers the email' do
- expect {
- post :create, message: @message
- }.to change {ActionMailer::Base.deliveries.size}.by(1)
+ context 'when user is a moderator' do
+ before { sign_in Fabricate(:user, moderator: true) }
+ it 'delivers the email' do
+ expect {
+ post :create, message: @message
+ }.to change {ActionMailer::Base.deliveries.size}.by(1)
+ end
+
+ describe 'delivered message' do
+ before :each do
+ post :create, message: @message
+ end
+
+ it "returns http success" do
+ response.should be_redirect
+ end
+
+ it 'delivers the mail with the subject that we wanted to' do
+ ActionMailer::Base.deliveries.last.subject.should == @message.subject
+ end
+
+ it 'delivers the mail with the body that we wanted to' do
+ ActionMailer::Base.deliveries.last.body.to_s.should match @message.body
+ end
+ end
end
- describe 'delivered message' do
- before :each do
+ context 'when user is not a moderator' do
+ before do
+ sign_in Fabricate(:user)
post :create, message: @message
end
+ it_behaves_like 'unauthorized'
+ end
- it "returns http success" do
- response.should be_redirect
- end
+ context 'when user is a guest' do
+ before { post :create, message: @message }
+ it_behaves_like 'unauthorized'
+ end
+ end
- it 'delivers the mail with the subject that we wanted to' do
- ActionMailer::Base.deliveries.last.subject.should == @message.subject
+ describe "POST 'create' for a diffusion" do
+ context 'when user is a moderator' do
+ before { sign_in Fabricate(:user, moderator: true) }
+ it "returns http success" do
+ expect {
+ post 'create', message: diffusion
+ }.to change {ActionMailer::Base.deliveries.size}.by(diffusion.email.size)
end
+ end
- it 'delivers the mail with the body that we wanted to' do
- ActionMailer::Base.deliveries.last.body.to_s.should match @message.body
+ context 'when user is not a moderator' do
+ before do
+ sign_in Fabricate(:user)
+ post :create, message: diffusion
end
+ it_behaves_like 'unauthorized'
end
- end
- describe "POST 'create' for a diffusion" do
- it "returns http success" do
- @diffusion = Fabricate.build(:diffusion)
- expect {
- post 'create', message: @diffusion
- }.to change {ActionMailer::Base.deliveries.size}.by(@diffusion.email.size)
+ context 'when user is a guest' do
+ before { post :create, message: diffusion }
+ it_behaves_like 'unauthorized'
end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.