diff --git a/Gemfile b/Gemfile
index b8121c7ee5..771ddb6ce7 100644
--- a/Gemfile
+++ b/Gemfile
@@ -57,4 +57,5 @@ group :development, :test do
gem 'cucumber-rails-training-wheels'
gem 'database_cleaner'
gem 'capybara'
+ gem 'pry'
end
diff --git a/Gemfile.lock b/Gemfile.lock
index 64eb36cc1c..26794b0ec3 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -1,5 +1,5 @@
GEM
- remote: http://rubygems.org/
+ remote: https://rubygems.org/
specs:
RedCloth (4.2.9)
abstract (1.0.0)
@@ -87,6 +87,8 @@ 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)
@@ -94,6 +96,11 @@ GEM
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)
@@ -141,6 +148,8 @@ 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)
@@ -148,10 +157,12 @@ GEM
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)
@@ -193,6 +204,7 @@ DEPENDENCIES
kaminari
mini_magick (~> 1.3.3)
pg
+ pry
rails (~> 3.0.10)
rake (~> 0.9.2)
recaptcha
@@ -205,3 +217,6 @@ DEPENDENCIES
thin
uuidtools (~> 2.1.1)
webrat
+
+BUNDLED WITH
+ 1.11.2
diff --git a/app/controllers/admin/categories_controller.rb b/app/controllers/admin/categories_controller.rb
index b7026f8f29..7a04df9507 100644
--- a/app/controllers/admin/categories_controller.rb
+++ b/app/controllers/admin/categories_controller.rb
@@ -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.js {
@category = Category.new
}
end
@@ -25,12 +25,17 @@ def destroy
def new_or_edit
@categories = Category.find(:all)
- @category = Category.find(params[:id])
+ @category = case params[:id]
+ when nil
+ Category.new
+ else
+ Category.find(params[:id])
+ end
@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
diff --git a/app/views/admin/content/_form.html.erb b/app/views/admin/content/_form.html.erb
index 7b85db61c8..f041eced52 100644
--- a/app/views/admin/content/_form.html.erb
+++ b/app/views/admin/content/_form.html.erb
@@ -16,7 +16,7 @@
<%= _("Status:") %>
<%= @article.state.to_s.downcase %> Change
+
+ <% if current_user.admin? && @article.title != nil %>
+ Merge Articles
+
+ <% end %>
-
diff --git a/features/manage_articles.feature b/features/manage_articles.feature
new file mode 100644
index 0000000000..4334c118ba
--- /dev/null
+++ b/features/manage_articles.feature
@@ -0,0 +1,13 @@
+Feature: Manage Articles
+ In order to organize articles
+ As an admin
+ I want to add a new category
+
+ Background:
+ Given the blog is set up
+ And I am logged into the admin panel
+
+ Scenario: Create category page is shown
+ Given I am on the admin page
+ When I follow "Categories"
+ Then I should be on the new or edit category page
diff --git a/features/manage_categories.feature b/features/manage_categories.feature
new file mode 100644
index 0000000000..a5a45aa0c4
--- /dev/null
+++ b/features/manage_categories.feature
@@ -0,0 +1,23 @@
+Feature: Manage Categories
+ In order to better organize articles
+ As an admin
+ I want to add or edit a category
+
+ Background:
+ Given the blog is set up
+ And I am logged into the admin panel
+
+ Scenario: Category page is shown
+ Given I am on the admin page
+ When I follow "Categories"
+ Then I should be on the category page
+
+ Scenario: Create and edit category
+ Given I am on the category page
+ When I fill in "category_name" with "mishmash"
+ And I press "Save"
+ Then I should see "Category was successfully saved."
+ And I should see "mishmash"
+ And I should have 1 new category
+ When I follow "mishmash"
+ Then I should see "mishmash"
diff --git a/features/merge_articles.feature b/features/merge_articles.feature
new file mode 100644
index 0000000000..7c3ed28b49
--- /dev/null
+++ b/features/merge_articles.feature
@@ -0,0 +1,26 @@
+Feature: Merge articles
+ As a blog administrator
+ In order to improve UX
+ I want to be able to merge articles with other similar articles
+
+ Background:
+ Given the blog is set up
+
+ Scenario: Merge articles form is not shown on new article view
+ Given I am on the admin page
+ And I am logged into the admin panel
+ When I follow "New Article"
+ Then I should not see "Merge Articles"
+
+ Scenario: Merge articles field is not shown for non admins
+ Given I am on the admin content page
+ And I am logged into the admin panel as a non admin
+ When I follow "Edit"
+ Then I should be on the admin content page
+ And I should see "Error, you are not allowed to perform this action"
+
+ Scenario: Merge articles field is shown for admins
+ Given I am on the admin content page
+ And I am logged into the admin panel
+ When I follow "Edit"
+ Then I should see "Merge Articles"
diff --git a/features/step_definitions/web_steps.rb b/features/step_definitions/web_steps.rb
index 6315105872..eaa8b4e69a 100644
--- a/features/step_definitions/web_steps.rb
+++ b/features/step_definitions/web_steps.rb
@@ -41,6 +41,12 @@ def with_scope(locator)
:profile_id => 1,
:name => 'admin',
:state => 'active'})
+ User.create!({:login => 'not admin',
+ :password => 'bbbbb',
+ :email => 'nojoe@snow.com',
+ :profile_id => 2,
+ :name => 'not admin',
+ :state => 'active'})
end
And /^I am logged into the admin panel$/ do
@@ -55,6 +61,26 @@ def with_scope(locator)
end
end
+And /^I am logged into the admin panel as a non admin$/ do
+ visit '/accounts/login'
+ fill_in 'user_login', :with => 'not admin'
+ fill_in 'user_password', :with => 'bbbbb'
+ click_button 'Login'
+ if page.respond_to? :should
+ page.should have_content('Login successful')
+ else
+ assert page.has_content?('Login successful')
+ end
+end
+
+# And /^I am not an admin$/ do
+# User.name != 'admin'
+# end
+#
+# And /^I am an admin$/ do
+# User.name == 'admin'
+# end
+
# Single-line step scoper
When /^(.*) within (.*[^:])$/ do |step, parent|
with_scope(parent) { When step }
@@ -162,6 +188,12 @@ def with_scope(locator)
end
end
+Then /^I should have (\d+) new category$/ do |count|
+ # expect{Category.count}.to change{Category.count}.by(arg1)
+ Category.count.should == count.to_i + 1
+end
+
+
Then /^the "([^"]*)" field(?: within (.*))? should contain "([^"]*)"$/ do |field, parent, value|
with_scope(parent) do
field = find_field(field)
@@ -250,7 +282,7 @@ def with_scope(locator)
end
end
end
-
+
Then /^(?:|I )should be on (.+)$/ do |page_name|
current_path = URI.parse(current_url).path
if current_path.respond_to? :should
@@ -264,8 +296,8 @@ def with_scope(locator)
query = URI.parse(current_url).query
actual_params = query ? CGI.parse(query) : {}
expected_params = {}
- expected_pairs.rows_hash.each_pair{|k,v| expected_params[k] = v.split(',')}
-
+ expected_pairs.rows_hash.each_pair{|k,v| expected_params[k] = v.split(',')}
+
if actual_params.respond_to? :should
actual_params.should == expected_params
else
diff --git a/features/support/paths.rb b/features/support/paths.rb
index e7e00e5d89..71580b6b45 100644
--- a/features/support/paths.rb
+++ b/features/support/paths.rb
@@ -17,6 +17,17 @@ def path_to(page_name)
'/'
when /^the new article page$/
'/admin/content/new'
+ when /^the admin page$/
+ '/admin'
+ when /^the category page$/
+ '/admin/categories/new'
+ when /^the admin content page$/
+ '/admin/content'
+ when /^the admin edit content page$/
+ '/admin/content/edit'
+ when /^the category edit page$/
+ '/admin/catogories/edit'
+
# Add more mappings here.
# Here is an example that pulls values out of the Regexp:
diff --git a/spec/controllers/admin/categories_controller_spec.rb b/spec/controllers/admin/categories_controller_spec.rb
index bb290f4a0d..e0f6061419 100644
--- a/spec/controllers/admin/categories_controller_spec.rb
+++ b/spec/controllers/admin/categories_controller_spec.rb
@@ -16,6 +16,18 @@
assert_response :redirect, :action => 'index'
end
+ describe "test_new" do
+ it "should render template new" do
+ get :new
+ assert_template 'new'
+ end
+
+ it "should redirect to new template" do
+ get :new
+ assert_response :success
+ end
+ end
+
describe "test_edit" do
before(:each) do
get :edit, :id => Factory(:category).id
@@ -48,7 +60,7 @@
it 'should render destroy template' do
assert_response :success
- assert_template 'destroy'
+ assert_template 'destroy'
end
end
@@ -62,5 +74,5 @@
assert_raise(ActiveRecord::RecordNotFound) { Category.find(test_id) }
end
-
+
end