Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
7591abd
Addin gpry
Dreedle Mar 28, 2016
7bc474e
Cucumber test for viewing new category page seems to work. Adding con…
Dreedle Mar 28, 2016
ee9127b
Fleshing out edit action in admin categories controller to be analogo…
Dreedle Mar 28, 2016
8500d5e
Wrote rspec and cucumber tests that fail when the original bug is pre…
Dreedle Mar 28, 2016
d50917d
Removing pry require
Dreedle Mar 28, 2016
6620396
Able to create and edit categories
Dreedle Mar 29, 2016
7bfec19
Merge branch 'createcat'
Dreedle Mar 29, 2016
cc0b3f8
Adding cucumber tests for creating and editing categories
Dreedle Mar 29, 2016
a086d02
Adding cuke stubbed tests for merge article feature. Able to log in a…
Dreedle Mar 29, 2016
541bb51
Mapping edit article path for cucumber test
Dreedle Mar 29, 2016
cca8085
Adding content creation to blog setup in cuke tests
Dreedle Mar 29, 2016
df4466e
Changing content creation to article creation in cuke tests
Dreedle Mar 29, 2016
80bdce7
Improving cuke test for edit category
Dreedle Mar 29, 2016
7fa43e8
Improving create category cuke test
Dreedle Mar 29, 2016
44c15ea
Adding cuke tests for editing articles (authorization)
Dreedle Mar 29, 2016
838d007
Removing edit articles from paths.rb
Dreedle Mar 29, 2016
33eb38d
Red cuke test for article merging as admin vs not admin
Dreedle Mar 29, 2016
6fd7d63
Moving merge article feature tests conerning authorization to their o…
Dreedle Mar 29, 2016
3218a8b
Stubbing out cuke tests for merge_article.feature
Dreedle Mar 29, 2016
088d55e
Specs for merge article feature (red) are complete
Dreedle Mar 30, 2016
f65e97e
Adding html for merge article form
Dreedle Mar 30, 2016
1c341fc
Adding better errors and binding of caller
Dreedle Mar 30, 2016
45abe42
Merge article is present for admin but not non-admin (cuke tests pass)
Dreedle Mar 30, 2016
77c3b04
Cuke test passing for feature not accessible when article is new
Dreedle Mar 30, 2016
4545acb
Trying to get green on cuke test for succesful merge
Dreedle Mar 30, 2016
096c9e6
Improved cuke tests for merge, though no test for author merge yet. T…
Dreedle Mar 30, 2016
cd29d3b
Cuke test passing for combining article text
Dreedle Mar 30, 2016
7b4dbc5
Adding conditional to admin new content view to make rspecs pass
Dreedle Mar 30, 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 Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ gem 'acts_as_tree_rails3'
gem 'recaptcha', :require => 'recaptcha/rails', :branch => 'rails3'

group :development, :test do
gem 'better_errors'
gem 'binding_of_caller'
gem 'ruby-debug19'
gem 'factory_girl', '~> 2.2'
gem 'webrat'
Expand All @@ -57,4 +59,5 @@ group :development, :test do
gem 'cucumber-rails-training-wheels'
gem 'database_cleaner'
gem 'capybara'
gem 'pry'
end
25 changes: 24 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
GEM
remote: http://rubygems.org/
remote: https://rubygems.org/
specs:
RedCloth (4.2.9)
abstract (1.0.0)
Expand Down Expand Up @@ -34,6 +34,11 @@ GEM
addressable (2.3.2)
archive-tar-minitar (0.5.2)
arel (2.0.10)
better_errors (0.0.8)
coderay
erubis
binding_of_caller (0.7.2)
debug_inspector (>= 0.0.1)
bluecloth (2.2.0)
builder (2.1.2)
capybara (1.1.2)
Expand All @@ -60,6 +65,7 @@ GEM
cucumber-rails (>= 1.1.1)
daemons (1.1.9)
database_cleaner (0.8.0)
debug_inspector (0.0.2)
diff-lcs (1.1.3)
erubis (2.6.6)
abstract (>= 1.0.0)
Expand Down Expand Up @@ -87,13 +93,20 @@ GEM
i18n (>= 0.4.0)
mime-types (~> 1.16)
treetop (~> 1.4.8)
method_source (0.6.7)
ruby_parser (>= 2.3.1)
mime-types (1.19)
mini_magick (1.3.3)
subexec (~> 0.0.4)
multi_json (1.3.6)
nokogiri (1.5.5)
pg (0.14.1)
polyglot (0.3.3)
pry (0.9.7.4)
coderay (~> 0.9.8)
method_source (~> 0.6.7)
ruby_parser (>= 2.3.1)
slop (~> 2.1.0)
rack (1.2.5)
rack-mount (0.6.14)
rack (>= 1.0.0)
Expand Down Expand Up @@ -141,17 +154,21 @@ GEM
ruby-debug-base19 (>= 0.11.19)
ruby_core_source (0.1.5)
archive-tar-minitar (>= 0.5.2)
ruby_parser (3.8.1)
sexp_processor (~> 4.1)
rubypants (0.2.0)
rubyzip (0.9.9)
selenium-webdriver (2.25.0)
childprocess (>= 0.2.5)
libwebsocket (~> 0.1.3)
multi_json (~> 1.0)
rubyzip
sexp_processor (4.7.0)
simplecov (0.6.4)
multi_json (~> 1.0)
simplecov-html (~> 0.5.3)
simplecov-html (0.5.3)
slop (2.1.0)
sqlite3 (1.3.6)
subexec (0.0.4)
thin (1.5.0)
Expand Down Expand Up @@ -179,6 +196,8 @@ DEPENDENCIES
acts_as_list
acts_as_tree_rails3
addressable (~> 2.1)
better_errors
binding_of_caller
bluecloth (~> 2.1)
capybara
coderay (~> 0.9)
Expand All @@ -193,6 +212,7 @@ DEPENDENCIES
kaminari
mini_magick (~> 1.3.3)
pg
pry
rails (~> 3.0.10)
rake (~> 0.9.2)
recaptcha
Expand All @@ -205,3 +225,6 @@ DEPENDENCIES
thin
uuidtools (~> 2.1.1)
webrat

BUNDLED WITH
1.11.2
20 changes: 14 additions & 6 deletions app/controllers/admin/categories_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ class Admin::CategoriesController < Admin::BaseController
def index; redirect_to :action => 'new' ; end
def edit; new_or_edit; end

def new
def new
respond_to do |format|
format.html { new_or_edit }
format.js {
format.html {new_or_edit}
format.js {
@category = Category.new
}
end
Expand All @@ -24,13 +24,21 @@ def destroy
private

def new_or_edit
if params[:action] == "new"
@category = Category.new
elsif params[:action] == "edit" && params[:id]

Choose a reason for hiding this comment

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

Thought: Does the params[:action] in this elsif as well as the one below change the conditional, or could you just use params[:id]

@category = Category.find(params[:id])
@category.attributes = params[:category]
elsif params[:action] == "edit" && !params[:id]
@category = Category.new
@category.attributes = params[:category]
end

@categories = Category.find(:all)
@category = Category.find(params[:id])
@category.attributes = params[:category]
if request.post?
respond_to do |format|
format.html { save_category }
format.js do
format.js do
@category.save
@article = Article.new
@article.categories << @category
Expand Down
19 changes: 13 additions & 6 deletions app/controllers/admin/content_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def auto_complete_for_article_keywords

def index
@search = params[:search] ? params[:search] : {}

@articles = Article.search_with_pagination(@search, {:page => params[:page], :per_page => this_blog.admin_display_elements})

if request.xhr?
Expand Down Expand Up @@ -44,14 +44,21 @@ def destroy
flash[:error] = _("Error, you are not allowed to perform this action")
return(redirect_to :action => 'index')
end

return(render 'admin/shared/destroy') unless request.post?

@record.destroy
flash[:notice] = _("This article was deleted successfully")
redirect_to :action => 'index'
end

def merge
@article = Article.find(params[:id])
@article.merge_with(params[:other_article_id]["other_article_id"])
redirect_to admin_content_path
end


def insert_editor
editor = 'visual'
editor = 'simple' if params[:editor].to_s == 'simple'
Expand All @@ -77,7 +84,7 @@ def attachment_box_add

def attachment_save(attachment)
begin
Resource.create(:filename => attachment.original_filename, :mime => attachment.content_type.chomp,
Resource.create(:filename => attachment.original_filename, :mime => attachment.content_type.chomp,
:created_at => Time.now).write_to_disk(attachment)
rescue => e
logger.info(e.message)
Expand All @@ -92,7 +99,7 @@ def autosave
@article.text_filter = current_user.text_filter if current_user.simple_editor?

get_fresh_or_existing_draft_for_article

@article.attributes = params[:article]
@article.published = false
set_article_author
Expand Down Expand Up @@ -159,13 +166,13 @@ def new_or_edit
@article.keywords = Tag.collection_to_string @article.tags
@article.attributes = params[:article]
# TODO: Consider refactoring, because double rescue looks... weird.

@article.published_at = DateTime.strptime(params[:article][:published_at], "%B %e, %Y %I:%M %p GMT%z").utc rescue Time.parse(params[:article][:published_at]).utc rescue nil

if request.post?
set_article_author
save_attachments

@article.state = "draft" if @article.draft

if @article.save
Expand Down
18 changes: 15 additions & 3 deletions app/models/article.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,17 @@ def initialize(*args)
end
end

def merge_with(other_article_id)
other_article = Article.find(other_article_id)
Article.transaction do

Choose a reason for hiding this comment

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

Yes! Definitely a transaction is good here. I think you can also use self.transaction

old_body = self.body
self.body = "#{old_body} <p>\r\n\t #{other_article.body} </p>\r\n"
self.comments << other_article.comments
self.save!
other_article.delete
end
end

def set_permalink
return if self.state == 'draft'
self.permalink = self.title.to_permalink if self.permalink.nil? or self.permalink.empty?
Expand All @@ -95,6 +106,7 @@ def has_child?
include Article::States

class << self

def last_draft(article_id)
article = Article.find(article_id)
while article.has_child?
Expand All @@ -104,10 +116,10 @@ def last_draft(article_id)
end

def search_with_pagination(search_hash, paginate_hash)

state = (search_hash[:state] and ["no_draft", "drafts", "published", "withdrawn", "pending"].include? search_hash[:state]) ? search_hash[:state] : 'no_draft'


list_function = ["Article.#{state}"] + function_search_no_draft(search_hash)

if search_hash[:category] and search_hash[:category].to_i > 0
Expand Down
6 changes: 3 additions & 3 deletions app/views/admin/categories/new.html.erb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<% @page_heading = _("Categories") %>

<div class='left_form'>
<!-- NOTE:
Do not modify :action=>"edit" since the autograder depends on it
<!-- NOTE:
Do not modify :action=>"edit" since the autograder depends on it
-->
<%= form_tag :action=>"edit", :id => @category.id do %>
<%= error_messages_for 'category' %>
Expand Down Expand Up @@ -32,7 +32,7 @@
</div>
</div>
<div class='actions'>
<%= cancel_or_save %>
<%= cancel_or_save %>
</div>
<% end %>
</div>
Expand Down
3 changes: 1 addition & 2 deletions app/views/admin/categories/new.js.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@
$$('.top-layer').each(function(layer) { layer.remove(); });
event.stop();
});
<!-- Ok, it's just for Mister Perfect -->
cancel_link.writeAttribute('href', '#close_form');
<!-- Intercepts form submission -->
// <!-- Intercepts form submission -->
$$('.concrete form').each(function(cat_form) {
cat_form.observe('submit', function(event) {
cat_form.request({
Expand Down
8 changes: 4 additions & 4 deletions app/views/admin/content/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<div class='clearfix'>
<%= _("Status:") %> <strong><%= @article.state.to_s.downcase %></strong> <a href="#" onclick="Element.toggle('status'); return false">Change</a>
<ul class='inputs-list'>
<li id='status' style='display: none;'>
<li id='status' style='display: none;'>
<label for="article_published">
<%= check_box 'article', 'published' %>
<%= _("Published") %>
Expand Down Expand Up @@ -129,7 +129,7 @@
<div class='class'>
<%= text_field 'article', 'keywords', {:autocomplete => 'off', :style => 'width: 100%'} %>
</div>
<%= auto_complete_field 'article_keywords', { :url => { :action => "auto_complete_for_article_keywords"}, :tokens => ','}%>
<%= auto_complete_field 'article_keywords', { :url => { :action => "auto_complete_for_article_keywords"}, :tokens => ','}%>
</div>

<div class='separator'>
Expand All @@ -146,8 +146,8 @@
<ul id='attachments' class='inputs-list'>
<%= render 'admin/content/attachment', { :attachment_num => 1, :hidden => false } -%>
</ul>
</div>
</div>

</div>
</div>

</div>
4 changes: 4 additions & 0 deletions app/views/admin/content/new.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
<% @page_heading = _('New article') %>

<%= render "admin/shared/edit", { :form_type => "article", :form_action => { :action => "new", :id => @article.id , :class => ('autosave')} } %>

<% if @current_user && @current_user.admin? && @article.id %>
<%= render "admin/shared/merge" %>
<% end %>
17 changes: 17 additions & 0 deletions app/views/admin/shared/_merge.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

<div class='editor-left'>
<%= form_for @article, url: {controller: "admin/content", action: "merge", id: @article.id },
:html => { :class => "form" } do |f| %>
<h3><%= _("Merge Articles") %></h3>
<div class='class'>
<span>
Article ID
<%= text_field "other_article_id", "other_article_id", {:autocomplete => 'off', :style => 'width: 30%; margin-left: 10px'} %>
</span>
<div style="padding-top:10px">

Choose a reason for hiding this comment

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

Can you use a class here instead of inline style?

<%= f.submit "Merge", :class => 'btn' %>
</div>
</div>

<% end %>
</div>
Binary file added db/db_development
Binary file not shown.
Binary file added db/db_test
Binary file not shown.
23 changes: 23 additions & 0 deletions features/create_category.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Feature: Create Categories
As an admin
In order to organize my blog posts into categories
I want to create a category

Background:
Given the blog is set up
And I am logged into the admin panel

Scenario: New category page shown
Given I am on the new category page
Then I should see "Categories"

Scenario: Successfully create category
Given I am on the new category page
When I fill in "category_name" with "Foobar"
And I fill in "category_keywords" with "Lorem Ipsum"
And I fill in "category_description" with "Lorem Ipsum"
And I press "Save"
Then I should be on the new category page
And I should see "Category was successfully saved."
And I should see "Foobar"
And I should see "Lorem Ipsum"
29 changes: 29 additions & 0 deletions features/edit_article.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
Feature: Edit Articles
As a blog publisher or admin
In order to provide the best articles possible
I want to be able to edit articles

Background:
Given the blog is set up

Scenario: Successfully edit articles that belong to publisher
Given I am logged in as a blog publisher
Given the following article record
| title | body | published | user_id |
| "publisher article" | "hi here it is" | true | 2 |

And I am on the articles page
Then I should see "publisher article"
When I follow "Edit"
Then I should see "Publish settings"

Scenario: As publisher, cannot edit articles that do not belong to you.
Given I am logged in as a blog publisher
Given the following article record
| title | body | published | user_id |
| "admin article" | "hi here's another" | true | 1 |

And I am on the articles page
Then I should see "admin article"
When I follow "Edit"
Then I should see "Error, you are not allowed to perform this action"
Loading