Skip to content

Commit

Permalink
Customized Proposals#index for phase 1 and interlude. Refs euruko2013#15
Browse files Browse the repository at this point in the history
.
  • Loading branch information
nikosd committed Apr 21, 2013
1 parent 7448580 commit 23c330f
Show file tree
Hide file tree
Showing 6 changed files with 185 additions and 19 deletions.
1 change: 1 addition & 0 deletions app/controllers/proposals_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ def index

@withdrawn_proposals = Proposal.withdrawn.all
@proposals = Proposal.active.order('created_at desc').all
@suggested_proposal = current_user.proposals_without_own_votes.active.sample || Proposal.active.sample if current_user

respond_with @proposals
end
Expand Down
11 changes: 7 additions & 4 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,15 +136,18 @@ def authentication_links(container = :p)
['Facebook', '/auth/facebook']].map { |name, url| content_tag container, link_to(name, url) }.join("\n").html_safe
end

def countdown_to_submissions_end
submissions_end = Phase::ONE.ending_at
if submissions_end > DateTime.now
content_tag :span, '', id: 'counter', data: {countdown_end: submissions_end.to_i * 1000}
def countdown_to(phase_end)
if phase_end > DateTime.now
content_tag :span, '', id: 'counter', data: {countdown_end: phase_end.to_i * 1000}
else
content_tag :span, 'no time'
end
end

def countdown_to_phase_end
countdown_to current_phase.ending_at
end

protected
def markdown_parser(options = {})
@markdown_parser ||= Redcarpet::Markdown.new(Redcarpet::Render::HTML,
Expand Down
21 changes: 21 additions & 0 deletions app/models/phase.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,19 @@ def self.all
[ZERO, ONE, INTERLUDE, TWO, CONFIRMATION, LINEUP]
end

def self.last_submission_date
ONE.ending_at
end

def self.last_voting_date
INTERLUDE.ending_at
end

attr_accessor :name

attr_accessor :main_text
attr_accessor :countdown_text

attr_accessor :starting_at
attr_accessor :ending_at

Expand All @@ -30,6 +41,8 @@ def self.all

ZERO = Phase.new.tap do |p|
p.name = "Before the beginning"
p.main_text = "Be part of #{Settings.event_name}: we highly encourage you to submit as many proposals as you want, help the authors make theirs better and finally select the most interesting ones for the final agenda! What are you waiting for?"
p.countdown_text = "before the submissions open!"
p.starting_at = DateTime.new(1970, 1, 1)
p.ending_at = DateTime.parse('2013-03-28T00:00:00+2')

Expand All @@ -42,6 +55,8 @@ def self.all

ONE = Phase.new.tap do |p|
p.name = "Phase 1: Submissions"
p.main_text = "Be part of #{Settings.event_name}: we highly encourage you to submit as many proposals as you want, help the authors make theirs better and finally select the most interesting ones for the final agenda! What are you waiting for?"
p.countdown_text = "to submit, refine and discuss proposals!"
p.starting_at = DateTime.parse('2013-03-28T00:00:00+2')
p.ending_at = DateTime.parse('2013-04-24T00:00:00+3')

Expand All @@ -54,6 +69,8 @@ def self.all

INTERLUDE = Phase.new.tap do |p|
p.name = "Interlude"
p.main_text = "Make it <em>your</em> #{Settings.event_name}: select the finalists before the grand voting! We highly encourage you to go through every single proposal select the most interesting ones. After all, this is what the conference is all about! What are you waiting for?"
p.countdown_text = "to cast your votes that will define the finalists!"
p.starting_at = DateTime.parse('2013-04-24T00:00:00+3')
p.ending_at = DateTime.parse('2013-04-29T00:00:00+3')

Expand All @@ -66,6 +83,8 @@ def self.all

TWO = Phase.new.tap do |p|
p.name = "Phase 2: Final voting"
p.main_text = "This is it! This is the time you define #{Settings.event_name}! Make <strong>your</strong> ideal lineup."
p.countdown_text = "to define the conference schedule!"
p.starting_at = DateTime.parse('2013-04-29T00:00:00+3')
p.ending_at = DateTime.parse('2013-05-06T00:00:00+3')

Expand All @@ -78,6 +97,7 @@ def self.all

CONFIRMATION = Phase.new.tap do |p|
p.name = "Speakers confirmation"
p.main_text = ""
p.starting_at = DateTime.parse('2013-05-06T00:00:00+3')
p.ending_at = DateTime.parse('2013-05-09T00:00:00+3')

Expand All @@ -90,6 +110,7 @@ def self.all

LINEUP = Phase.new.tap do |p|
p.name = "Lineup announcement"
p.main_text = ""
p.starting_at = DateTime.parse('2013-05-09T00:00:00+3')
p.ending_at = DateTime.parse('2100-01-01T00:00:00+2')

Expand Down
2 changes: 1 addition & 1 deletion app/views/dashboard/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<h2>Your proposals</h2>

<div class="alert">
You have still <%= countdown_to_submissions_end %> to submit or edit a proposal!
You have still <%= countdown_to Phase.last_submission_date %> to submit or edit a proposal!
Since proposals are anonymised, other users will not see that you are the author of these. <%= link_to "Read more about the process", about_path %>.
</div>

Expand Down
22 changes: 11 additions & 11 deletions app/views/proposals/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
<div class="hero-unit">
<%= page_title "#{Settings.event_name} Call for Presentations" %>

<p>
Be part of <%= Settings.event_name %>:
we highly encourage you to submit as many proposals as you want,
help the authors make theirs better
and finally select the most interesting ones for the final agenda!
What are you waiting for?
</p>
<% if current_phase.main_text %>
<p><%= current_phase.main_text.html_safe %></p>
<% end %>

<p>
You have <%= countdown_to_submissions_end %> to submit, refine and discuss proposals!
</p>
<% if current_phase.countdown_text %>
<p>You have <%= countdown_to_phase_end %> <%= current_phase.countdown_text %></p>
<% end %>

<p>
<% if user_signed_in? %>
<%= link_to "Propose a talk", new_proposal_path, :class => 'btn btn-primary' %>
<% if can? :create, Proposal %>
<%= link_to "Propose a talk", new_proposal_path, :class => 'btn btn-primary' %>
<% elsif @suggested_proposal && can?(:vote, @suggested_proposal) %>
<%= link_to "Cast your votes!", proposal_path(@suggested_proposal), :class => 'btn btn-primary' %>
<% end %>
<% else %>
<div class="btn-group">
<%= link_to 'Join the party', '#', :class => 'btn btn-primary dropdown-toggle', :data => {:toggle => 'dropdown'} %>
Expand Down
147 changes: 144 additions & 3 deletions test/integration/proposal_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ class ProposalTest < IntegrationTestCase
context "As a visitor to the site" do
should "not see a link to propose a talk" do
visit proposals_path
assert !page.has_content?("Propose talk"), "link to propose talk should not be present!"
assert !page.has_content?("Propose a talk"), "link to propose talk should not be present!"
end

should "not see a link to vote for a talk" do
visit proposals_path
assert !page.has_content?("Cast your votes!"), "link to vote talks should not be present!"
end

should "not be able to propose a talk" do
Expand Down Expand Up @@ -67,6 +72,16 @@ class ProposalTest < IntegrationTestCase
sign_in @user
end

should "see a link to propose a talk" do
visit proposals_path
assert page.has_content?("Propose a talk"), "link to propose talk should be present!"
end

should "not see a link to vote for a talk" do
visit proposals_path
assert !page.has_content?("Cast your votes!"), "link to vote talks should not be present!"
end

context "and I propose a talk with all the required details" do
setup { propose_talk :title => "My Amazing Talk", :description => 'This talk is <script>pwned</script>amazing.' }

Expand Down Expand Up @@ -220,6 +235,132 @@ class ProposalTest < IntegrationTestCase
end
end

[Phase::INTERLUDE].each do |phase|
context "During '#{phase.name}'" do
setup do
Phase.stubs(:current).returns(phase)
end

context "As a visitor to the site" do
should "not see a link to propose a talk" do
visit proposals_path
assert !page.has_content?("Propose a talk"), "link to propose talk should not be present!"
end

should "not see a link to vote for a talk" do
visit proposals_path
assert !page.has_content?("Cast your votes!"), "link to vote talks should not be present!"
end

should "not be able to propose a talk" do
visit new_proposal_path
i_am_asked_to_sign_in
end

context "given a proposal already exists" do
setup do
@proposal = FactoryGirl.create(:proposal, :title => "Ruby Muby Schmuby")
end

should "be able to see the list of proposals" do
visit proposals_path
assert page.has_css?('ul.proposals')
end

should "be able to subscribe to the rss feed of proposals" do
visit proposals_path
assert page.has_css?("link[rel='alternate'][type='application/rss+xml'][href$='#{proposals_path(:format => :rss)}']")
visit proposals_path(:format => :rss)
assert_match %r{application/rss\+xml}, page.response_headers['Content-Type']
assert page.has_xpath?('.//item/title', :text => @proposal.title)
end

should "be able to read individual proposals" do
visit proposals_path
click_link "Ruby Muby Schmuby"
assert_page_has_proposal :title => "Ruby Muby Schmuby"
end

should "not see a link to edit a proposal" do
visit proposals_path
click_link "Ruby Muby Schmuby"
assert !page.has_content?("Edit proposal"), "link to edit proposal should not be present"
end

should "not be able to edit a proposal" do
visit edit_proposal_path(@proposal)
i_am_asked_to_sign_in
end

should "my page view be tracked" do
assert_difference(lambda { @proposal.impressionist_count }, 1) do
visit proposal_path(@proposal)
end
end
end
end

context "Given I am logged in" do
setup do
@user = FactoryGirl.create(:user)
sign_in @user
end

should "not see a link to propose a talk" do
visit proposals_path
assert !page.has_content?("Propose a talk"), "link to propose talk should not be present!"
end

context "given a proposal already exists" do
setup do
@proposal = FactoryGirl.create(:proposal, :title => "Ruby Muby Schmuby")
end

should "see a link to vote for a talk" do
visit proposals_path
assert page.has_content?("Cast your votes!"), "link to vote talks should be present!"
end

should "be able to see the list of proposals" do
visit proposals_path
assert page.has_css?('ul.proposals')
end

should "be able to subscribe to the rss feed of proposals" do
visit proposals_path
assert page.has_css?("link[rel='alternate'][type='application/rss+xml'][href$='#{proposals_path(:format => :rss)}']")
visit proposals_path(:format => :rss)
assert_match %r{application/rss\+xml}, page.response_headers['Content-Type']
assert page.has_xpath?('.//item/title', :text => @proposal.title)
end

should "be able to read individual proposals" do
visit proposals_path
click_link "Ruby Muby Schmuby"
assert_page_has_proposal :title => "Ruby Muby Schmuby"
end

should "not see a link to edit a proposal" do
visit proposals_path
click_link "Ruby Muby Schmuby"
assert !page.has_content?("Edit proposal"), "link to edit proposal should not be present"
end

should "not be able to edit a proposal" do
visit edit_proposal_path(@proposal)
i_am_not_authorized
end

should "my page view be tracked" do
assert_difference(lambda { @proposal.impressionist_count }, 1) do
visit proposal_path(@proposal)
end
end
end
end
end
end

[Phase.all - [Phase::ONE, Phase::INTERLUDE]].flatten.each do |phase|
context "During '#{phase.name}'" do
setup do
Expand All @@ -229,7 +370,7 @@ class ProposalTest < IntegrationTestCase
context "As a visitor to the site" do
should "not see a link to propose a talk" do
visit proposals_path
assert !page.has_content?("Propose talk"), "link to propose talk should not be present!"
assert !page.has_content?("Propose a talk"), "link to propose talk should not be present!"
end

should "not be able to propose a talk" do
Expand Down Expand Up @@ -288,7 +429,7 @@ class ProposalTest < IntegrationTestCase

should "not see a link to propose a talk" do
visit proposals_path
assert !page.has_content?("Propose talk"), "link to propose talk should not be present!"
assert !page.has_content?("Propose a talk"), "link to propose talk should not be present!"
end

should "not be able to propose a talk" do
Expand Down

0 comments on commit 23c330f

Please sign in to comment.