-
Notifications
You must be signed in to change notification settings - Fork 20
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
Added new feature - merging articles #31
base: master
Are you sure you want to change the base?
Changes from all commits
73f14ca
8affeba
e197c54
11c3441
bafbcb1
c495c6d
cea1ca8
fa42bbe
e2fd415
e67a30a
8388959
18234f2
a094dc5
4542d5b
e42d3ff
f6c1b6a
68c604a
7d15d8d
c2ff602
d3574d7
41eb299
4ca8dce
be933d0
9f1725e
3e897e3
1fb480c
926e998
36f85c3
77772e2
5a75c27
589907e
8efd204
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
config/mail.yml | ||
*.log | ||
*~ | ||
db/db_development | ||
db/db_test | ||
db/*.sqlite* | ||
db/schema.rb | ||
.*.swp | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -104,10 +104,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 | ||
|
@@ -416,6 +416,17 @@ def access_by?(user) | |
user.admin? || user_id == user.id | ||
end | ||
|
||
def merge_with(other_article_id) | ||
# keep title and author from article 1 (self) | ||
article_2 = Article.find(other_article_id.to_i) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Even though you are merging with another article, it doesn't really make sense to call this variable |
||
# combine body and comments from both articles | ||
self.body += " #{article_2.body}" | ||
self.comments += article_2.comments | ||
self.save | ||
article_2.delete | ||
return self | ||
end | ||
|
||
protected | ||
|
||
def set_published_at | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<div> | ||
<h3>Merge Articles</h3> | ||
<form action="/admin/content/merge/<%= @article.id %>" method="get"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a named path you can use here instead of a string? |
||
<div class='clearfix'> | ||
<label for="merge_with" style="width: 55px; margin-right: 5px;"><%= _("Article ID")%></label> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Eek! Is there a class you can use to do this styling instead of styling directly in the label? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wanted to but I couldn't figure out where I was supposed to put CSS definitions! This would have been something I would have asked my team about best practice I think... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cool - makes sense to me! |
||
<div class='input'> | ||
<input class="large" id="merge_id" name="merge_with" size="30" type="text"> | ||
</div> | ||
</div> | ||
<br /> | ||
<button class="btn" type="submit" value="submit" id="submit_merge">Merge</button> | ||
</form> | ||
</div> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
Feature: Create Categories | ||
As a blog administrator | ||
I want to be able to create Categories | ||
|
||
Background: | ||
Given the blog is set up | ||
And I am logged into the admin panel | ||
|
||
Scenario: Successfully create new Categories | ||
When I click on Categories | ||
Then I should be on the new category page | ||
When I fill in "category_name" with "Meow Meow" | ||
And I fill in "category_keywords" with "Cats" | ||
And I fill in "category_description" with "I like cats" | ||
And I press "Save" | ||
Then I should see "Meow Meow" | ||
And I should see "Cats" | ||
And I should see "I like cats" | ||
|
||
Scenario: Try to create a Category without a name | ||
When I click on Categories | ||
Then I should be on the new category page | ||
When I fill in "category_name" with "" | ||
And I press "Save" | ||
Then page should have error message "Category could not be saved." |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
Feature: Edit Categories | ||
As a blog administrator | ||
I want to be able to edit Categories | ||
|
||
Background: | ||
Given the blog is set up | ||
And I am logged into the admin panel | ||
And I have an existing Category named "Meow" | ||
|
||
Scenario: Successfully edit existing Categories | ||
When I click on Categories | ||
Then I should be on the new category page | ||
When I follow "Meow" | ||
Then I should be on the edit category page | ||
When I fill in "category_name" with "Meow Meow" | ||
And I fill in "category_keywords" with "Cats Meow" | ||
And I fill in "category_description" with "I really really like cats" | ||
And I press "Save" | ||
Then I should see "Meow Meow" | ||
And I should see "Cats Meow" | ||
And I should see "I really really like cats" | ||
|
||
Scenario: Try to edit a Category and remove the name | ||
When I click on Categories | ||
Then I should be on the new category page | ||
When I follow "Meow" | ||
Then I should be on the edit category page | ||
When I fill in "category_name" with "" | ||
And I press "Save" | ||
Then page should have error message "Category could not be saved." |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
Feature: Merge Articles | ||
As a blog administrator | ||
In order to keep the world spam-free | ||
I want to be able to merge similar articles on my blog | ||
|
||
Background: | ||
Given the blog is set up | ||
And I am logged into the admin panel | ||
And an article exists with title "Entry 1" and text "This is entry 1" and author "I Like Cats" | ||
|
||
Scenario: Admin can successfully merge articles | ||
Given I am on the edit article page | ||
Then I should see "Merge Articles" | ||
When I fill in "merge_with" with "3" | ||
And I press "Merge" | ||
Then I should be on the admin content page | ||
And I should see "Article was successfully merged" | ||
And I should see "Hello World!" | ||
And I should see "admin" | ||
And I should not see "Entry 1" | ||
And I should not see "I Like Cats" | ||
When I follow "Hello World!" | ||
Then I should see "Welcome to Typo. This is your first article. Edit or delete it, then start blogging! This is entry 1" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
Feature: Merge Articles | ||
As a non-admin blog user | ||
I can't have special things | ||
So I can't merge articles | ||
|
||
Background: | ||
Given the blog is set up | ||
And an article exists with title "Entry 1" and text "This is entry 1" and author "I Like Cats" | ||
|
||
Scenario: Non-admin cannot merge articles | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it could make sense to put this scenario in the feature in the merge_articles rather than in this separate file. |
||
Given I am on the edit article page | ||
Then I should not see "Merge Articles" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So you're doing two
find_by_id
s here, which is going to make the same database query twice. I'd recommend storing the result of this above the conditional so it will only do this database query once.