Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ config/mail.yml
*~
db/*.sqlite*
db/schema.rb
db/db_development
db/db_test
.*.swp
.*.swo
.DS_Store
Expand Down
5 changes: 4 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 @@ -205,3 +205,6 @@ DEPENDENCIES
thin
uuidtools (~> 2.1.1)
webrat

BUNDLED WITH
1.11.2
13 changes: 8 additions & 5 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.js {
@category = Category.new
}
end
Expand All @@ -25,12 +25,16 @@ def destroy

def new_or_edit
@categories = Category.find(:all)
@category = Category.find(params[:id])
if params[:id] == nil
@category = Category.new
else
@category = Category.find_by_id(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
Expand All @@ -50,5 +54,4 @@ def save_category
end
redirect_to :action => 'new'
end

end
3 changes: 3 additions & 0 deletions app/controllers/categories_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
class CategoriesController < GroupingController
# index - inherited
# show - inherited
def new

Choose a reason for hiding this comment

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

Do you need this since the bulk of the work is in the admin?

Copy link
Author

Choose a reason for hiding this comment

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

Just checked my git status and didn't commit this deletion. Thanks!

Choose a reason for hiding this comment

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

This is still in here - maybe missing another commit?

render 'new'
end
end
8 changes: 4 additions & 4 deletions app/views/admin/categories/new.html.erb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<% @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 %>
<%= form_tag :action=>"new", :id => @category.id do %>
<%= error_messages_for 'category' %>
<div class='clearfix'>
<label for="category_name"><%= _("Name")%></label>
Expand Down Expand Up @@ -32,7 +32,7 @@
</div>
</div>
<div class='actions'>
<%= cancel_or_save %>
<%= cancel_or_save %>
</div>
<% end %>
</div>
Expand Down
1 change: 1 addition & 0 deletions config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
# your test database is "scratch space" for the test suite and is wiped
# and recreated between test runs. Don't rely on the data there!
config.cache_classes = true


# Log error messages when you accidentally call methods on nil.
config.whiny_nils = true
Expand Down
Binary file added db/db_development
Binary file not shown.
Binary file added db/db_test
Binary file not shown.
44 changes: 44 additions & 0 deletions features/manage_categories.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
Feature: Create category
As an admin
In order to categorize my blogs
I want create and manage blog categories

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

Scenario: Create category
Given I am a user
When I am on the homepage
Then I should be able to click "Categories"
And I should be able add a new category

Scenario: Successfully visit categories page
Given there are no categories
When I follow "Categories"
When I fill in "Name" with "dogs"
Then I should be able to click "Categories"
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.

It might also be good to add a "I should see 'dogs'"

Copy link
Author

Choose a reason for hiding this comment

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

Added, thanks!

And I should see "dogs"

Scenario: Create a Category
When I follow "Categories"
And I fill in "Name" with "dogs"
And I fill in "Keywords" with "dogs"
And I fill in "Permalink" with "www.test.com"
And I fill in "Description" with "fun"
And I press "Save"
Then I should see "Category was successfully saved."

Choose a reason for hiding this comment

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

Same comment re: seeing the newly created category

Copy link
Author

Choose a reason for hiding this comment

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

Added, thanks!

And I should see "dogs"

Scenario: Edit a Category
When I go to the edit page for "dogs"
And I fill in "Description" with "playful"
And I press "Save"
Then I should see "Category was successfully saved."
And I should see "dogs"

Scenario: Cancel editing
When I got to the edit page for "dogs"
And I press "Cancel"
Then I should go to "Categories"
45 changes: 42 additions & 3 deletions features/step_definitions/web_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,51 @@ def with_scope(locator)
end
end

Given /^I am logged in as a user$/ do
User.create!({:login => 'joesmith',
:password => 'password',
:email => 'example@example.com',
:profile_id => 3,
:name => 'Joe',
:state => 'active'})
visit '/accounts/logout'
visit '/accounts/login'
fill_in 'user_login', :with => 'joesmith'
fill_in 'user_password', :with => 'password'
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 }
end

# Multi-line step scoper
When /^I create a new category named $category/ do |category|
visits new_category_path
fills_in 'Category', :with => Category
clicks_button 'Create'
end

Then /^I should see that a category named category$ exists/ do |category|
response.body.should =~ Regexp.new(category)
end

When /^I edit a new category named category$/ do |category|
visits edit_category_path
fills_in 'Category', :with => Category
clicks_button 'Create'
end

Then /^I should see that a category named category$ exists/ do |category|
response.body.should =~ Regexp.new(category)
end

When /^(.*) within (.*[^:]):$/ do |step, parent, table_or_string|
with_scope(parent) { When "#{step}:", table_or_string }
end
Expand Down Expand Up @@ -250,7 +289,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 +303,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
3 changes: 3 additions & 0 deletions features/support/paths.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ def path_to(page_name)
'/'
when /^the new article page$/
'/admin/content/new'

when /^the edit page for "(.*)"$/
admin_categories_path(Category.find_by_name($1))

# Add more mappings here.
# Here is an example that pulls values out of the Regexp:
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
13 changes: 11 additions & 2 deletions spec/controllers/admin/categories_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@
request.session = { :user => henri.id }
end

it "renders the 'new' template" do

Choose a reason for hiding this comment

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

these tests are good!

get :new
expect(response).to render_template :new
end

it "successfully loads 'new' page" do
get :new
expect(response.status).to eq 200
end

it "test_index" do
get :index
assert_response :redirect, :action => 'index'
Expand Down Expand Up @@ -48,7 +58,7 @@

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

Expand All @@ -62,5 +72,4 @@

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

end
8 changes: 3 additions & 5 deletions spec/models/category_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,19 @@
c.articles.size.should == 2
c.published_articles.size.should == 1
end

it "empty permalink should be converted" do
Factory(:blog)
c = Category.create(:name => "test 1")
c.permalink.should == "test-1"
end

it "category with permalink should not have permalink generated" do
Factory(:blog)
c = Category.create(:name => "Test 2", :permalink => "yeah-nice-one")
c.permalink.should == "yeah-nice-one"
end

end

describe Category do
Expand All @@ -45,5 +45,3 @@
it { should == 'http://myblog.net/category/software' }
end
end