Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create Merge Feature #34

Open
wants to merge 38 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
ea8b763
complete setup
jbuechs Mar 28, 2016
22db627
add better errors
jbuechs Mar 28, 2016
87a2f98
add pry
jbuechs Mar 28, 2016
4ebdd0c
create stubs for adding and editing category features
jbuechs Mar 28, 2016
96056fa
check for id in params to determine whether new or editing category
jbuechs Mar 28, 2016
f58f517
bugfix for empty category name
jbuechs Mar 28, 2016
e8c3f91
update dbs
jbuechs Mar 28, 2016
75a3724
add tests for new category
jbuechs Mar 28, 2016
6261cd6
create cucumber tests for creating a category
jbuechs Mar 28, 2016
77c2ebb
create feature tests for category
jbuechs Mar 28, 2016
657c1a4
create tests for valid and invalid updating of category
jbuechs Mar 28, 2016
42e9c93
spec/controllers/accounts_controller_spec.rb
jbuechs Mar 28, 2016
b28f533
add update category tests to cucumber
jbuechs Mar 28, 2016
93c5397
add update category tests to cucumber
jbuechs Mar 28, 2016
09f2a3c
update dbs
jbuechs Mar 28, 2016
c9adfa0
remove db files from commit
jbuechs Mar 28, 2016
e37d605
remove pry
jbuechs Mar 28, 2016
8018e78
change test description for clarity
jbuechs Mar 28, 2016
79615d1
create test for adding merge to new article form
jbuechs Mar 29, 2016
abf1587
add test that contributor does not see merge form
jbuechs Mar 29, 2016
e0229ec
showing merge form for admin
jbuechs Mar 29, 2016
4517eb7
create test for merging text
jbuechs Mar 29, 2016
1edbaaa
format tables
jbuechs Mar 29, 2016
08dec6a
separate article_merge tests into admin and not admin
jbuechs Mar 29, 2016
8c73be9
update admin features to not show merge on new page
jbuechs Mar 29, 2016
310076a
complete tests for merging text of two articles
jbuechs Mar 29, 2016
0f506a4
implement feature for merging text of two articles
jbuechs Mar 29, 2016
11791a6
create test for merging comments
jbuechs Mar 31, 2016
9a8c0a0
merge comments
jbuechs Mar 31, 2016
d659aa6
create test for deleting merged article
jbuechs Mar 31, 2016
4a26383
delete merged article
jbuechs Mar 31, 2016
0f6e8e5
delete merged article
jbuechs Mar 31, 2016
95942e1
Merge branch 'master' of github.com:jbuechs/typo
jbuechs Mar 31, 2016
38b7ee5
remove pry and rename variable to be more meaningful
jbuechs Mar 31, 2016
85b115d
move merge function to model and create transaction
jbuechs Apr 1, 2016
b5d8a96
add db file to gitignore
jbuechs Apr 1, 2016
c0acb92
only query all articles when admin and editing
jbuechs Apr 1, 2016
89ecebe
refactor merging comments
jbuechs Apr 1, 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 .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ config/mail.yml
*~
db/*.sqlite*
db/schema.rb
db/db_development
db/db_test
db/db_test-journal
.*.swp
.*.swo
.DS_Store
Expand Down
6 changes: 6 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,10 @@ group :development, :test do
gem 'cucumber-rails-training-wheels'
gem 'database_cleaner'
gem 'capybara'
gem "pry"
end

group :development do
gem "better_errors"
gem "binding_of_caller"
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
4 changes: 2 additions & 2 deletions app/controllers/admin/categories_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def destroy

def new_or_edit
@categories = Category.find(:all)
@category = Category.find(params[:id])
@category = params[:id] ? (Category.find(params[:id])) : (Category.new)
@category.attributes = params[:category]
if request.post?
respond_to do |format|
Expand All @@ -43,7 +43,7 @@ def new_or_edit
end

def save_category
if @category.save!
if @category.save
flash[:notice] = _('Category was successfully saved.')
else
flash[:error] = _('Category could not be saved.')
Expand Down
8 changes: 8 additions & 0 deletions app/controllers/admin/content_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'base64'
require 'pry'

module Admin; end
class Admin::ContentController < Admin::BaseController
Expand Down Expand Up @@ -113,6 +114,12 @@ def autosave
render :text => nil
end

def merge
@article = Article.find(params["id"])
@article.merge_with(params[:merge_with])
redirect_to :action => 'edit', id: @article.id
end

protected

def get_fresh_or_existing_draft_for_article
Expand Down Expand Up @@ -140,6 +147,7 @@ def do_add_or_remove_fu
def real_action_for(action); { 'add' => :<<, 'remove' => :delete}[action]; end

def new_or_edit
@articles = Article.all if current_user.admin? && params[:action] == "edit"
id = params[:id]
id = params[:article][:id] if params[:article] && params[:article][:id]
@article = Article.get_or_build_article(id)
Expand Down
11 changes: 11 additions & 0 deletions app/models/article.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,17 @@ def has_child?
Article.exists?({:parent_id => self.id})
end

def merge_with(merge_id)
Article.transaction do
merge_article = Article.find(merge_id)
self.body += merge_article.body
self.comments += merge_article.comments
merge_article.comments.reload
merge_article.destroy
self.save
end
end

attr_accessor :draft, :keywords

has_state(:state,
Expand Down
10 changes: 10 additions & 0 deletions app/views/admin/shared/_edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,13 @@
<%= render :partial => "form" %>

<% end %>

<% if current_user.admin? && params[:id] %>
<h4>You can associate the following resources</h4>
<h5>Merge Articles</h5>
<%= form_tag({action: :merge, :id => @article.id}, {:remote => true, :class => className}) do %>
<% options = options_from_collection_for_select(@articles, 'id', 'title') %>
<%= select_tag 'merge_with', options %>
<%= submit_tag("Merge", {:class => 'btn primary'}) %>
<% end %>
<% end %>
54 changes: 54 additions & 0 deletions features/article_merge_admin.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
Feature: Article Merge

Choose a reason for hiding this comment

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

These scenarios look great


As a blog administrator
In order to keep my blog organized
I want to be able to merge similar articles on my blog

Background:
Given the blog is set up
Given I am logged into the admin panel
Given the following article records
| title | author | body | user_id | published |
| Hello! | Ada Lovelace | Hello, world! | 2 | true |
| Goodbye! | Admin | Goodbye, waterfalls! | 1 | true |
Given the following comment records
| author | body | article_id | published |
| Ada Lovelace | Hello, article! | 3 | true |
| Charles Babbage | Goodbye, article. | 4 | true |

Scenario: Display Merge Articles Button to Admin on Edit Page
Given I am on the edit article page for "Hello!"
Then I should see "Merge Articles"
And I should see "Merge" button

Scenario: Do not Display Merge Articles Button to Admin on New Page
And I am on the new article page
Then I should not see "Merge Articles"
And I should not see "Merge" button

Scenario: Merge text of two articles
Given I am on the edit article page for "Hello!"
And I select "Goodbye!" from the dropdown
And I press "Merge"
Then I should be on the edit article page for "Hello!"
When I go to the article page for "Hello!"
Then I should see "Goodbye, waterfalls!"
And I should see "Hello, world!"

Scenario: Merge the comments of two articles
Given I am on the article page for "Hello!"
And the "Hello!" article should have 1 comment
When I go to the edit article page for "Hello!"
And I select "Goodbye!" from the dropdown
And I press "Merge"
Then the "Hello!" article should have 2 comments

Scenario: Delete the merged article
Given I am on the home page
Then I should see "Goodbye!"
When I go to the edit article page for "Hello!"
And I select "Goodbye!" from the dropdown
And I press "Merge"
When I go to the homepage
Then I should not see "Goodbye!"

23 changes: 23 additions & 0 deletions features/article_merge_not_admin.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Feature: Article Merge

As a blog contributor
In order to keep my blog organized
I want to be able to merge similar articles on my blog

Background:
Given the blog is set up
Given I am logged in as contributor to the admin panel
Given the following article records
| title | author | body | user_id |
| Hello, world! | Ada Lovelace | Hello, world! | 2 |
| Goodbye! | Admin | Goodbye, waterfalls! | 1 |

Scenario: Do not Display Merge Articles Button on Edit Page
Given I am on the edit article page for "Hello, world!"
Then I should not see "Merge Articles"
And I should not see "Merge" button

Scenario: Do not Display Merge Articles Button on New Page
Given I am on the new article page
Then I should not see "Merge Articles"
And I should not see "Merge" button
44 changes: 44 additions & 0 deletions features/category.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
Feature: Categories
As a blog administrator
In order to share my thoughts with the world
I want to be able to create and manage categories to my blog

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

Scenario: Successfully add new category
Given I am on the new category page
When I fill in "category_name" with "Foobar"
And I press "Save"
Then I should be on the new category page
And I should see "Foobar"
And page should have success message "Category was successfully saved."

Scenario: Error message with blank new category
Given I am on the new category page
And I press "Save"
Then I should be on the new category page
And page should have error message "Category could not be saved."

Scenario: Update a category
Given the following category records
| name |
| Foobar |
And I am on the edit page for "Foobar"
When I fill in "category_name" with "Foobaz"
And I press "Save"
Then I should be on the new category page
And I should see "Foobaz"
And page should have success message "Category was successfully saved."

Scenario: Error message with blank update category
Given the following category records
| name |
| Foobar |
And I am on the edit page for "Foobar"
When I fill in "category_name" with ""
And I press "Save"
Then I should be on the new category page
And I should see "Foobar"
And page should have error message "Category could not be saved."
45 changes: 45 additions & 0 deletions features/step_definitions/web_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ def with_scope(locator)
:profile_id => 1,
:name => 'admin',
:state => 'active'})
User.create!({:login => 'ada',
:password => 'lovelace',
:email => '[email protected]',
:profile_id => 2,
:name => 'ada',
:state => 'active'})
end

And /^I am logged into the admin panel$/ do
Expand All @@ -55,6 +61,18 @@ def with_scope(locator)
end
end

Given /^I am logged in as contributor to the admin panel$/ do
visit '/accounts/login'
fill_in 'user_login', :with => 'ada'
fill_in 'user_password', :with => 'lovelace'
click_button 'Login'
if page.respond_to? :should
page.should have_content('Login successful')
else
assert page.has_content?('Login successful')
end
end

# Single-line step scoper
When /^(.*) within (.*[^:])$/ do |step, parent|
with_scope(parent) { When step }
Expand Down Expand Up @@ -276,3 +294,30 @@ def with_scope(locator)
Then /^show me the page$/ do
save_and_open_page
end

Then /^page should have (.+) message "([^\"]*)"$/ do |type, text|
page.has_css?("div.#{type}", :text => text, :visible => true)
end

Given /^the following (.+) records$/ do |factory, table|
table.hashes.each do |hash|
Factory(factory, hash)
end
end

Then /^I should see "([^"]*)" button/ do |name|
should have_button name
end

Then /^I should not see "(.*?)" button$/ do |name|
should have_no_button name
end

Given /^I select "(.*?)" from the dropdown$/ do |title|
select title, from: "merge_with"
end

Given /^the "(.*?)" article should have (\d+) comments*$/ do |title, num|
article = Article.where(title: title).first
article.comments.count.should == num.to_i
end
1 change: 1 addition & 0 deletions features/support/env.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# files.

require 'cucumber/rails'
require "#{Rails.root}/spec/factories"

# Capybara defaults to XPath selectors rather than Webrat's default of CSS3. In
# order to ease the transition to Capybara we set the default here. If you'd
Expand Down
Loading