From d365741765b18ae145c71627c1401d136902648c Mon Sep 17 00:00:00 2001 From: Conner Smith Date: Thu, 6 Feb 2014 14:09:09 -0600 Subject: [PATCH 1/5] fixed some syntax problems on admin user edit --- app/views/admin/users/edit.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/admin/users/edit.html.erb b/app/views/admin/users/edit.html.erb index aee14b0..d53e00f 100644 --- a/app/views/admin/users/edit.html.erb +++ b/app/views/admin/users/edit.html.erb @@ -13,7 +13,7 @@ <%= f.input :email, as: :email %> <%= f.input :password, as: :password %> <%= f.input :password_confirmation, as: :password %> -

Current Role <%= @user.role %>

+

Current Roles: <%= @user.roles %>

<%= f.input :roles, collection: [:user, :admin], include_blank: false %> <%= f.submit "Save" %> <% end %> From 2e2c685d5a8ed56ea998cab8d9061d69c24319fa Mon Sep 17 00:00:00 2001 From: Conner Smith Date: Thu, 6 Feb 2014 15:41:35 -0600 Subject: [PATCH 2/5] added news indexes to home and tournament, tests passed --- app/controllers/admin/news_controller.rb | 3 +++ app/controllers/home_controller.rb | 6 +++-- app/controllers/matches_controller.rb | 1 + app/controllers/tournaments_controller.rb | 1 + app/models/comment.rb | 4 ++-- app/models/news.rb | 4 +++- app/models/tournament.rb | 3 ++- app/models/user.rb | 1 + .../cpanel/_admincp_manage_news.html.erb | 8 +++---- app/views/application/_index_news.html.erb | 14 +++++++++++ app/views/application/_show_comments.html.erb | 3 +-- app/views/application/_show_news.html.erb | 8 +++++++ ...tml.erb => _submit_match_comment.html.erb} | 0 app/views/home/_home_signed_in.html.erb | 2 +- app/views/home/home.html.erb | 7 ++++++ app/views/matches/show.html.erb | 2 +- app/views/news/show.html.erb | 9 ++------ app/views/tournaments/show.html.erb | 4 ++++ spec/features/admincp_create_news_spec.rb | 6 +++++ spec/features/comments_spec.rb | 10 ++++++++ spec/features/news_spec.rb | 23 +++++++++++++++++++ spec/models/news_spec.rb | 5 ---- 22 files changed, 98 insertions(+), 26 deletions(-) create mode 100644 app/views/application/_index_news.html.erb create mode 100644 app/views/application/_show_news.html.erb rename app/views/application/{_submit_comment.html.erb => _submit_match_comment.html.erb} (100%) create mode 100644 spec/features/comments_spec.rb create mode 100644 spec/features/news_spec.rb delete mode 100644 spec/models/news_spec.rb diff --git a/app/controllers/admin/news_controller.rb b/app/controllers/admin/news_controller.rb index 66263c8..259d5ad 100644 --- a/app/controllers/admin/news_controller.rb +++ b/app/controllers/admin/news_controller.rb @@ -30,4 +30,7 @@ def create end + def destroy + end + end diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index fe20212..b7039a1 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -1,9 +1,11 @@ class HomeController < ApplicationController def home + @news = News.where(newsable_id: 0) if user_signed_in? - @teams = current_user.teams - @tournaments = current_user.tournaments + @user = current_user + @teams = @user.teams + @tournaments = @user.tournaments end end end diff --git a/app/controllers/matches_controller.rb b/app/controllers/matches_controller.rb index 8f09f46..3a96288 100644 --- a/app/controllers/matches_controller.rb +++ b/app/controllers/matches_controller.rb @@ -5,6 +5,7 @@ def show @match = Match.find(params[:id]) @home_team = @match.home_team.team @away_team = @match.away_team.team + @comments = @match.comments end def edit diff --git a/app/controllers/tournaments_controller.rb b/app/controllers/tournaments_controller.rb index b414790..0e2f16f 100644 --- a/app/controllers/tournaments_controller.rb +++ b/app/controllers/tournaments_controller.rb @@ -11,6 +11,7 @@ def show @active_tournament_team = nil @tournament_team = TournamentTeam.new @matches = Match.current_week_matches(@tournament) + @news = @tournament.news @current_user_teams = [] if user_signed_in? current_user.teams.each do |team| diff --git a/app/models/comment.rb b/app/models/comment.rb index e9225ca..a04a19f 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -2,10 +2,10 @@ class Comment < ActiveRecord::Base MAX_LENGTH = 8000 attr_accessible :content, :user_id belongs_to :commentable, :polymorphic => true - + validates_presence_of :content, :user_id validate :is_of_valid_length - + def is_of_valid_length if content.empty? or content.length > MAX_LENGTH errors.add(:content, "cannot be empty") diff --git a/app/models/news.rb b/app/models/news.rb index 151f75f..e70e5f1 100644 --- a/app/models/news.rb +++ b/app/models/news.rb @@ -1,5 +1,7 @@ class News < ActiveRecord::Base - attr_accessible :headline, :description, :content, :newsable_id + attr_accessible :headline, :description, :content, :newsable_id, :user belongs_to :newsable, :polymorphic => true + has_many :comments, :as => :commentable, :dependent => :destroy + belongs_to :user end diff --git a/app/models/tournament.rb b/app/models/tournament.rb index 9b040ee..8092268 100644 --- a/app/models/tournament.rb +++ b/app/models/tournament.rb @@ -1,5 +1,5 @@ class Tournament < ActiveRecord::Base - attr_accessible :description, :name, :rules, :current_week_num + attr_accessible :description, :name, :rules, :current_week_num, :news validates_presence_of :name validates_inclusion_of :active, :in => [true, false] @@ -8,6 +8,7 @@ class Tournament < ActiveRecord::Base has_many :tournament_teams, :dependent => :destroy has_many :teams, through: :tournament_teams has_many :matches, :dependent => :destroy + has_many :news, :as => :newsable, :dependent => :destroy def scheduler teams = TournamentTeam.where(tournament_id: self.id).order(:rank) diff --git a/app/models/user.rb b/app/models/user.rb index a39ee50..5dd3275 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -18,6 +18,7 @@ class User < ActiveRecord::Base has_many :memberships has_many :teams, through: :memberships has_many :tournaments, through: :teams + has_many :news roles_attribute :roles_mask roles :admin, :user, :banned diff --git a/app/views/admin/cpanel/_admincp_manage_news.html.erb b/app/views/admin/cpanel/_admincp_manage_news.html.erb index 6f16315..d5cd935 100644 --- a/app/views/admin/cpanel/_admincp_manage_news.html.erb +++ b/app/views/admin/cpanel/_admincp_manage_news.html.erb @@ -12,12 +12,12 @@ <% @news.each do |news| %> - <%= link_to news.title, news_path(news) %> - <%= news.source%> - <%= news.user %> + <%= link_to news.headline, news_path(news) %> + <%= news.newsable_type %> + <%= news.user.username %> <%= news.created_at.strftime("%B %d,%Y") %> <%= link_to "edit", edit_admin_news_path(news), :id => "edit-#{news.id}" %> - <%= link_to "delete", destroy_admin_news_path(news), method: :delete, data: { confirm: "Are you sure?" }%> + <%= link_to "delete", admin_news_path(news), method: :delete, data: { confirm: "Are you sure?" }%> <% end %> <% paginate @news, :remote => true %> diff --git a/app/views/application/_index_news.html.erb b/app/views/application/_index_news.html.erb new file mode 100644 index 0000000..e0d501d --- /dev/null +++ b/app/views/application/_index_news.html.erb @@ -0,0 +1,14 @@ +<% if @news.any? %> + <% @news.each do |news| %> +
+

<%= news.headline %>

+ +

Created at <%= news.created_at %> by <%= news.user.username %>

+ +

<%= news.description %>

+

<%= link_to "read more...", news_path(news)%>

+
+ + + <% end %> +<% end %> diff --git a/app/views/application/_show_comments.html.erb b/app/views/application/_show_comments.html.erb index af28902..af3b8c8 100644 --- a/app/views/application/_show_comments.html.erb +++ b/app/views/application/_show_comments.html.erb @@ -1,7 +1,6 @@

comments

- <% @comments = @match.comments %> <% if @comments.any? %> <% @comments.each do |comment| %> <%= render :partial => "comment", :locals => { :comment => comment } %> @@ -10,4 +9,4 @@ No comments yet. <% end %>
-
\ No newline at end of file + diff --git a/app/views/application/_show_news.html.erb b/app/views/application/_show_news.html.erb new file mode 100644 index 0000000..877a9ea --- /dev/null +++ b/app/views/application/_show_news.html.erb @@ -0,0 +1,8 @@ +

<%= @news.headline %>

+

Created at <%= @news.created_at %> by <%= @news.user.username %>

+
+
+

<%=raw @news.content %>

+
+
+ diff --git a/app/views/application/_submit_comment.html.erb b/app/views/application/_submit_match_comment.html.erb similarity index 100% rename from app/views/application/_submit_comment.html.erb rename to app/views/application/_submit_match_comment.html.erb diff --git a/app/views/home/_home_signed_in.html.erb b/app/views/home/_home_signed_in.html.erb index da25f27..f2a54de 100644 --- a/app/views/home/_home_signed_in.html.erb +++ b/app/views/home/_home_signed_in.html.erb @@ -6,7 +6,7 @@ <% else %>
<% if @tournaments.any? %> - You are participating in + You are participating in <% num_tournaments = @tournaments.length %> <% if num_tournaments == 1 %> <% tournament = @tournaments.first %> diff --git a/app/views/home/home.html.erb b/app/views/home/home.html.erb index 4989521..bf7b3ef 100644 --- a/app/views/home/home.html.erb +++ b/app/views/home/home.html.erb @@ -9,3 +9,10 @@ <% end %>
+ +
+
+

general news

+
+ <%= render 'index_news' %> +
diff --git a/app/views/matches/show.html.erb b/app/views/matches/show.html.erb index 30eb548..67c9758 100644 --- a/app/views/matches/show.html.erb +++ b/app/views/matches/show.html.erb @@ -8,7 +8,7 @@ <%= render 'show_comments' %> -<%= render 'submit_comment' %> +<%= render 'submit_match_comment' %>
diff --git a/app/views/news/show.html.erb b/app/views/news/show.html.erb index 952c5f6..fb5e991 100644 --- a/app/views/news/show.html.erb +++ b/app/views/news/show.html.erb @@ -1,7 +1,2 @@ -

<%= @news.headline %>

-
-

<%= @news.description %>

-
-

<%=raw @news.content %>

-
-
+<%= render 'show_news' %> +<%= link_to "Back", :back %> diff --git a/app/views/tournaments/show.html.erb b/app/views/tournaments/show.html.erb index 34cca25..4212051 100644 --- a/app/views/tournaments/show.html.erb +++ b/app/views/tournaments/show.html.erb @@ -15,6 +15,10 @@ <% end %> <% end %>
+
+

news

+ <%= render('index_news')%> +

rankings

<% if @teams.any? %> diff --git a/spec/features/admincp_create_news_spec.rb b/spec/features/admincp_create_news_spec.rb index 4960d8d..1e33ae9 100644 --- a/spec/features/admincp_create_news_spec.rb +++ b/spec/features/admincp_create_news_spec.rb @@ -24,6 +24,12 @@ expect(page).to have_content(news.content) end + it "can be editted by an admin" do + end + + it "can be deleted by an admin" do + end + end def manage diff --git a/spec/features/comments_spec.rb b/spec/features/comments_spec.rb new file mode 100644 index 0000000..91ef33f --- /dev/null +++ b/spec/features/comments_spec.rb @@ -0,0 +1,10 @@ +require 'spec_helper' + +describe "Comments" do + it "needs to be tested" do + pending + end + + it "can be deleted by admins" do + end +end diff --git a/spec/features/news_spec.rb b/spec/features/news_spec.rb new file mode 100644 index 0000000..b93ec13 --- /dev/null +++ b/spec/features/news_spec.rb @@ -0,0 +1,23 @@ +require 'spec_helper' + +describe "News" do + let!(:user) { FactoryGirl.create(:user) } + let!(:news) { FactoryGirl.create(:news, newsable_type: "General", newsable_id: 0, user_id: user.id)} + let!(:tournament) { FactoryGirl.create(:tournament) } + let!(:tournament_news) { FactoryGirl.create(:news, newsable_type: "Tournament", newsable_id: tournament.id, user_id: user.id) } + + it "will appear on the main page if source is general" do + visit root_path + expect(page).to have_content(news.description) + end + + it "will appear on tournament main page if source is tournament" do + visit tournament_path(tournament) + expect(page).to have_content(news.description) + end + + it "can be commented on" do + pending + end + +end diff --git a/spec/models/news_spec.rb b/spec/models/news_spec.rb deleted file mode 100644 index 10b1492..0000000 --- a/spec/models/news_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'spec_helper' - -describe News do - pending "add some examples to (or delete) #{__FILE__}" -end From 28ecaa1cb7591c023e0419ea14c1c020ba94aeb2 Mon Sep 17 00:00:00 2001 From: Conner Smith Date: Thu, 6 Feb 2014 16:10:30 -0600 Subject: [PATCH 3/5] added edit and delete news --- app/controllers/admin/news_controller.rb | 27 +++++++++++++++++++ .../cpanel/_admincp_manage_news.html.erb | 4 +-- app/views/admin/news/edit.html.erb | 2 ++ app/views/admin/news/new.html.erb | 8 +----- .../application/_admin_news_form.html.erb | 9 +++++++ spec/features/admincp_create_news_spec.rb | 12 +++++++++ 6 files changed, 53 insertions(+), 9 deletions(-) create mode 100644 app/views/admin/news/edit.html.erb create mode 100644 app/views/application/_admin_news_form.html.erb diff --git a/app/controllers/admin/news_controller.rb b/app/controllers/admin/news_controller.rb index 259d5ad..762a8db 100644 --- a/app/controllers/admin/news_controller.rb +++ b/app/controllers/admin/news_controller.rb @@ -30,7 +30,34 @@ def create end + def edit + @news = News.find(params[:id]) + @sources = ["General"] + @tournaments = Tournament.where("active = true").each { |tourny| @sources << tourny.name } + end + + def update + @news = News.find(params[:id]) + if @news.update_attributes(params[:news]) + flash[:notice] = "News successfully added!" + redirect_to news_path(@news.id) + else + flash[:alert] = "Failed to add news." + render :edit + end + + end + def destroy + @news = News.find(params[:id]) + + if @news.delete + flash[:notice] = "News deleted." + redirect_to admin_root_path + else + flash[:alert] = "Unable to delete News." + redirect_to admin_root_path + end end end diff --git a/app/views/admin/cpanel/_admincp_manage_news.html.erb b/app/views/admin/cpanel/_admincp_manage_news.html.erb index d5cd935..ff3b1e5 100644 --- a/app/views/admin/cpanel/_admincp_manage_news.html.erb +++ b/app/views/admin/cpanel/_admincp_manage_news.html.erb @@ -16,8 +16,8 @@ <%= news.newsable_type %> <%= news.user.username %> <%= news.created_at.strftime("%B %d,%Y") %> - <%= link_to "edit", edit_admin_news_path(news), :id => "edit-#{news.id}" %> - <%= link_to "delete", admin_news_path(news), method: :delete, data: { confirm: "Are you sure?" }%> + <%= link_to "edit", edit_admin_news_path(news), :id => "edit-news-#{news.id}" %> + <%= link_to "delete", admin_news_path(news), method: :delete, id: "delete-news-#{news.id}", data: { confirm: "Are you sure?" }%> <% end %> <% paginate @news, :remote => true %> diff --git a/app/views/admin/news/edit.html.erb b/app/views/admin/news/edit.html.erb new file mode 100644 index 0000000..55f09d4 --- /dev/null +++ b/app/views/admin/news/edit.html.erb @@ -0,0 +1,2 @@ +

edit news

+<%= render 'admin_news_form' %> diff --git a/app/views/admin/news/new.html.erb b/app/views/admin/news/new.html.erb index 58e34f8..3803c24 100644 --- a/app/views/admin/news/new.html.erb +++ b/app/views/admin/news/new.html.erb @@ -1,8 +1,2 @@

add news

-<%= simple_form_for([:admin, @news]) do |f| %> - <%= f.input :newsable_id, collection: @sources, label: "Source" %> - <%= f.input :headline %> - <%= f.input :description %> - <%= f.input :content, as: :text, :input_html => { :rows => "15", :class =>"span5"} %> - <%= f.submit "Save" %> -<% end %> +<%= render 'admin_news_form' %> diff --git a/app/views/application/_admin_news_form.html.erb b/app/views/application/_admin_news_form.html.erb new file mode 100644 index 0000000..7421bcb --- /dev/null +++ b/app/views/application/_admin_news_form.html.erb @@ -0,0 +1,9 @@ +<%= simple_form_for([:admin, @news]) do |f| %> + <% if @news.newsable_type.nil? %> + <%= f.input :newsable_id, collection: @sources, label: "Source", include_blank: true %> + <% end %> + <%= f.input :headline %> + <%= f.input :description %> + <%= f.input :content, as: :text, :input_html => { :rows => "15", :class =>"span5"} %> + <%= f.submit "Save" %> +<% end %> diff --git a/spec/features/admincp_create_news_spec.rb b/spec/features/admincp_create_news_spec.rb index 1e33ae9..21c2787 100644 --- a/spec/features/admincp_create_news_spec.rb +++ b/spec/features/admincp_create_news_spec.rb @@ -3,6 +3,7 @@ describe "News" do let!(:tournament1) {FactoryGirl.create(:tournament)} let!(:admin) {FactoryGirl.create(:user)} + let!(:news) { FactoryGirl.create(:news, newsable_type: "General", newsable_id: 0, user: admin)} before do admin.roles = :admin @@ -25,9 +26,20 @@ end it "can be editted by an admin" do + visit admin_root_path + click_on "edit-news-#{news.id}" + fill_in "Headline", with: "new headline" + click_on "Save" + editted_news = News.find(news.id) + expect(editted_news.headline).to eq("new headline") + expect(editted_news.newsable_type).to eq("General") end it "can be deleted by an admin" do + prev = News.count + visit admin_root_path + click_on "delete-news-#{news.id}" + expect(News.count).to eq(prev - 1) end end From 49775c2d18957a2a1a110c12a0d42103068d9241 Mon Sep 17 00:00:00 2001 From: Conner Smith Date: Thu, 6 Feb 2014 16:56:12 -0600 Subject: [PATCH 4/5] added comments to news, refactored comment code a little, all tests pass --- app/controllers/comments_controller.rb | 21 +++++++++++++------ app/controllers/news_controller.rb | 7 ++++--- app/models/comment.rb | 3 ++- app/models/news.rb | 2 +- app/views/application/_comment.html.erb | 5 ++--- app/views/application/_show_comments.html.erb | 10 ++++----- app/views/application/_show_news.html.erb | 4 ++++ .../_submit_match_comment.html.erb | 2 +- .../application/_submit_news_comment.html.erb | 9 ++++++++ app/views/matches/show.html.erb | 4 +++- app/views/news/show.html.erb | 1 + config/routes.rb | 4 +++- spec/features/news_spec.rb | 7 ++++++- 13 files changed, 56 insertions(+), 23 deletions(-) create mode 100644 app/views/application/_submit_news_comment.html.erb diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index 4a230b4..1814398 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -1,6 +1,17 @@ class CommentsController < ApplicationController def create - if not params[:match_id].nil? + if not params[:news_id].nil? + @user = current_user + @news = News.find(params[:news_id]) + @comment = @news.comments.build(:content => params[:comment][:content], :user_id => @user.id ) + if @comment.save + flash[:notice] = "Comment accepted" + redirect_to :back + else + flash[:alert] = @comment.errors.full_messages.first + redirect_to news_path(@news) + end + elsif params[:match_id].nil? @match = Match.find(params[:match_id]) @home_team = @match.home_team.team @away_team = @match.away_team.team @@ -8,14 +19,12 @@ def create @comment = @match.comments.build( :content => params[:comment][:content], :user_id => current_user.id ) if @comment.save flash[:notice] = "Comment accepted" + redirect_to :back + else + flash[:alert] = @comment.errors.full_messages.first redirect_to tournament_match_path(@match.tournament, @match) - return end end end - - #TODO: cases for other comment types e.g. tournament, news comments - flash[:alert] = @comment.errors.full_messages.first - redirect_to tournament_match_path(@match.tournament, @match) end end diff --git a/app/controllers/news_controller.rb b/app/controllers/news_controller.rb index ddea538..da4a0fc 100644 --- a/app/controllers/news_controller.rb +++ b/app/controllers/news_controller.rb @@ -1,8 +1,9 @@ class NewsController < ApplicationController -def show - @news = News.find(params[:id]) -end + def show + @news = News.find(params[:id]) + @comments = @news.comments + end end diff --git a/app/models/comment.rb b/app/models/comment.rb index a04a19f..e8f8052 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -1,7 +1,8 @@ class Comment < ActiveRecord::Base MAX_LENGTH = 8000 - attr_accessible :content, :user_id + attr_accessible :content, :user, :user_id belongs_to :commentable, :polymorphic => true + belongs_to :user, :class_name => "User" validates_presence_of :content, :user_id validate :is_of_valid_length diff --git a/app/models/news.rb b/app/models/news.rb index e70e5f1..7f0c954 100644 --- a/app/models/news.rb +++ b/app/models/news.rb @@ -1,5 +1,5 @@ class News < ActiveRecord::Base - attr_accessible :headline, :description, :content, :newsable_id, :user + attr_accessible :headline, :description, :content, :newsable_id, :user, :user_id belongs_to :newsable, :polymorphic => true has_many :comments, :as => :commentable, :dependent => :destroy diff --git a/app/views/application/_comment.html.erb b/app/views/application/_comment.html.erb index be1feca..b88eb40 100644 --- a/app/views/application/_comment.html.erb +++ b/app/views/application/_comment.html.erb @@ -1,7 +1,6 @@ -<% @user = User.find(comment.user_id) %>
- <%= link_to @user.username, user_path(@user) %> + <%= link_to comment.user.username, user_path(comment.user) %>
<%= comment.updated_at %>
@@ -9,4 +8,4 @@
<%= comment.content %>
-
\ No newline at end of file +
diff --git a/app/views/application/_show_comments.html.erb b/app/views/application/_show_comments.html.erb index af3b8c8..3969fd1 100644 --- a/app/views/application/_show_comments.html.erb +++ b/app/views/application/_show_comments.html.erb @@ -2,11 +2,11 @@

comments

<% if @comments.any? %> - <% @comments.each do |comment| %> - <%= render :partial => "comment", :locals => { :comment => comment } %> - <% end %> + <% @comments.each do |comment| %> + <%= render :partial => "comment", :locals => { :comment => comment } %> + <% end %> <% else %> - No comments yet. - <% end %> + No comments yet. + <% end %>
diff --git a/app/views/application/_show_news.html.erb b/app/views/application/_show_news.html.erb index 877a9ea..1771988 100644 --- a/app/views/application/_show_news.html.erb +++ b/app/views/application/_show_news.html.erb @@ -4,5 +4,9 @@

<%=raw @news.content %>

+ <%= render('show_comments') %> + <% if user_signed_in? %> + <%= render('submit_news_comment') %> + <% end %> diff --git a/app/views/application/_submit_match_comment.html.erb b/app/views/application/_submit_match_comment.html.erb index f1ef21b..28e00e0 100644 --- a/app/views/application/_submit_match_comment.html.erb +++ b/app/views/application/_submit_match_comment.html.erb @@ -5,4 +5,4 @@ <%= f.input :content, :label => false, :as => :text, :input_html => { :cols => 50, :rows => 5 } %> <%= f.submit "Submit" %> <% end %> - \ No newline at end of file + diff --git a/app/views/application/_submit_news_comment.html.erb b/app/views/application/_submit_news_comment.html.erb new file mode 100644 index 0000000..a67b780 --- /dev/null +++ b/app/views/application/_submit_news_comment.html.erb @@ -0,0 +1,9 @@ +
+
+

submit comment

+ <%= simple_form_for [ @news, Comment.new ], :id => :comment do |f| %> + <%= f.input :content, :label => false, :as => :text, :input_html => { :cols => 50, :rows => 5 } %> + <%= f.submit "Submit" %> + <% end %> +
+
diff --git a/app/views/matches/show.html.erb b/app/views/matches/show.html.erb index 67c9758..6065b47 100644 --- a/app/views/matches/show.html.erb +++ b/app/views/matches/show.html.erb @@ -8,7 +8,9 @@ <%= render 'show_comments' %> -<%= render 'submit_match_comment' %> +<% if user_signed_in? %> + <%= render 'submit_match_comment' %> +<% end %> diff --git a/app/views/news/show.html.erb b/app/views/news/show.html.erb index fb5e991..02f3d0d 100644 --- a/app/views/news/show.html.erb +++ b/app/views/news/show.html.erb @@ -1,2 +1,3 @@ <%= render 'show_news' %> <%= link_to "Back", :back %> +
diff --git a/config/routes.rb b/config/routes.rb index b4b9203..0fa0e8e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,6 +1,8 @@ Ftwgl::Application.routes.draw do devise_for :users - resources :news, :only => [:show] + resources :news, :only => [:show] do + resources :comments, :only => [ :create ] + end resources :user, :only => [:show, :index] resources :teams, :only => [:new, :create, :show, :edit, :update, :index] resources :memberships, :only => [:create, :update, :destroy, :index] diff --git a/spec/features/news_spec.rb b/spec/features/news_spec.rb index b93ec13..8074cd3 100644 --- a/spec/features/news_spec.rb +++ b/spec/features/news_spec.rb @@ -17,7 +17,12 @@ end it "can be commented on" do - pending + prev = news.comments.count + sign_in_as(user) + visit news_path(news) + fill_in "comment_content", with: "This is a comment!" + click_on "Submit" + expect(news.comments.count).to eq(prev + 1) end end From c23a298ca36941e0682adffde4e13fc2935102f5 Mon Sep 17 00:00:00 2001 From: Conner Smith Date: Thu, 6 Feb 2014 17:06:53 -0600 Subject: [PATCH 5/5] some small edits --- app/assets/stylesheets/ftwgl.css.scss | 9 +++++++++ app/controllers/admin/news_controller.rb | 4 ++-- app/views/application/_index_news.html.erb | 2 +- app/views/tournaments/show.html.erb | 1 + 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/app/assets/stylesheets/ftwgl.css.scss b/app/assets/stylesheets/ftwgl.css.scss index cdb5611..4cad209 100644 --- a/app/assets/stylesheets/ftwgl.css.scss +++ b/app/assets/stylesheets/ftwgl.css.scss @@ -229,3 +229,12 @@ td{ .outer-heading{ font-size:24px; } + +.headline { + padding: 5px; + display: table; + margin: 0; + font-weight: 100; + font-size: 20px; + background-color: #cc5500; +} diff --git a/app/controllers/admin/news_controller.rb b/app/controllers/admin/news_controller.rb index 762a8db..77d5557 100644 --- a/app/controllers/admin/news_controller.rb +++ b/app/controllers/admin/news_controller.rb @@ -13,8 +13,8 @@ def create @news.newsable_id = 0 @news.newsable_type = "General" else - tournament = Tournament.where("name = #{@source}") - @news.newsable_id = tournament.id + @tournament = Tournament.where(name: "#{@source}") + @news.newsable_id = @tournament.last.id @news.newsable_type = "Tournament" end diff --git a/app/views/application/_index_news.html.erb b/app/views/application/_index_news.html.erb index e0d501d..2beddcc 100644 --- a/app/views/application/_index_news.html.erb +++ b/app/views/application/_index_news.html.erb @@ -1,7 +1,7 @@ <% if @news.any? %> <% @news.each do |news| %>
-

<%= news.headline %>

+

<%= news.headline %>

Created at <%= news.created_at %> by <%= news.user.username %>

diff --git a/app/views/tournaments/show.html.erb b/app/views/tournaments/show.html.erb index 4212051..ee0e1ca 100644 --- a/app/views/tournaments/show.html.erb +++ b/app/views/tournaments/show.html.erb @@ -17,6 +17,7 @@

news

+
<%= render('index_news')%>