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

Typo Blog: Fixing admin categories bug #9

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
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
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,5 @@ group :development, :test do
gem 'cucumber-rails-training-wheels'
gem 'database_cleaner'
gem 'capybara'
gem 'pry'
end
17 changes: 16 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 @@ -87,13 +87,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 +148,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 @@ -193,6 +204,7 @@ DEPENDENCIES
kaminari
mini_magick (~> 1.3.3)
pg
pry
rails (~> 3.0.10)
rake (~> 0.9.2)
recaptcha
Expand All @@ -205,3 +217,6 @@ DEPENDENCIES
thin
uuidtools (~> 2.1.1)
webrat

BUNDLED WITH
1.11.2
9 changes: 5 additions & 4 deletions app/controllers/admin/categories_controller.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
require 'pry'

Choose a reason for hiding this comment

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

eek! no check-ins with pry!

class Admin::CategoriesController < Admin::BaseController
cache_sweeper :blog_sweeper

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
Expand All @@ -25,12 +26,12 @@ 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|
format.html { save_category }
format.js do
format.js do
@category.save
@article = Article.new
@article.categories << @category
Expand Down
Binary file added db/db_development
Binary file not shown.
Binary file added db/db_test
Binary file not shown.
27 changes: 27 additions & 0 deletions features/manage_categories.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
Feature: Manage Categories
As a blog administrator
In order to organize my posts
I want to be able to add and edit categories

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

Scenario: Successfully add a category
Given there are no categories
When I follow "Categories"
And I fill in "Name" with "Test"
And I press "Save"
Then I should see "Category was successfully saved."
And I should see "Test"
And I should have 1 category

Choose a reason for hiding this comment

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

Nice!


Scenario: Successfully edit a category

Choose a reason for hiding this comment

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

These are two good scenarios. Should you add any for editing or error cases?

Given I have 1 category
When I follow "Categories"
When I follow "Edit"
And I fill in "Name" with "Another Test"
And I press "Save"
Then I should see "Category was successfully saved."
And I should see "Another Test"
And I should have 1 category
19 changes: 16 additions & 3 deletions features/step_definitions/web_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,19 @@
# * http://elabs.se/blog/15-you-re-cuking-it-wrong
#

Given /^there are no categories$/ do
Category.delete_all
end

Then /^I should have (\d+) category$/ do |num|
Category.all.count == num.to_i
end

Given /^I have (\d+) category$/ do |num|
num.to_i.times do
Category.create(name:"Test #{num}")
end
end

require 'uri'
require 'cgi'
Expand Down Expand Up @@ -250,7 +263,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
Expand All @@ -264,8 +277,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
Expand Down
2 changes: 1 addition & 1 deletion public/javascripts/ckeditor/config.bak
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ CKEDITOR.editorConfig = function( config )
config.PreserveSessionOnFileBrowser = true;
// Define changes to default configuration here. For example:
//config.language = '';
config.uiColor = '#E0ECFF';
config.uiColor = '#eee';
config.toolbar = 'Basic';
config.entities_greek = false;
config.entities_latin = false;
Expand Down
2 changes: 1 addition & 1 deletion public/javascripts/ckeditor/config.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ CKEDITOR.editorConfig = function( config )
config.PreserveSessionOnFileBrowser = true;
// Define changes to default configuration here. For example:
//config.language = '';
config.uiColor = '#E0ECFF';
config.uiColor = '#eee';
config.toolbar = 'Basic';
config.entities_greek = false;
config.entities_latin = false;
Expand Down
15 changes: 13 additions & 2 deletions spec/controllers/admin/categories_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@
assert_response :redirect, :action => 'index'
end

describe "test_new" do
before(:each) do
get :new
end

it "should render the new template" do
get "new"

Choose a reason for hiding this comment

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

Is this necessary since it is in the before each?

expect(subject).to render_template :new
end
end

describe "test_edit" do
before(:each) do
get :edit, :id => Factory(:category).id
Expand Down Expand Up @@ -48,7 +59,7 @@

it 'should render destroy template' do
assert_response :success
assert_template 'destroy'
assert_template 'destroy'
end
end

Expand All @@ -62,5 +73,5 @@

assert_raise(ActiveRecord::RecordNotFound) { Category.find(test_id) }
end

end