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

Hw/master #20

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
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_test
db/db_development
.*.swp
.*.swo
.DS_Store
Expand Down
1 change: 1 addition & 0 deletions .ruby-gemset
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
typo
1 change: 1 addition & 0 deletions .ruby-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.9.3
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ gem 'acts_as_tree_rails3'
gem 'recaptcha', :require => 'recaptcha/rails', :branch => 'rails3'

group :development, :test do
gem 'better_errors'
gem 'ruby-debug19'
gem 'factory_girl', '~> 2.2'
gem 'webrat'
Expand Down
9 changes: 8 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,9 @@ GEM
addressable (2.3.2)
archive-tar-minitar (0.5.2)
arel (2.0.10)
better_errors (0.0.8)
coderay
erubis
bluecloth (2.2.0)
builder (2.1.2)
capybara (1.1.2)
Expand Down Expand Up @@ -179,6 +182,7 @@ DEPENDENCIES
acts_as_list
acts_as_tree_rails3
addressable (~> 2.1)
better_errors
bluecloth (~> 2.1)
capybara
coderay (~> 0.9)
Expand All @@ -205,3 +209,6 @@ DEPENDENCIES
thin
uuidtools (~> 2.1.1)
webrat

BUNDLED WITH
1.11.2
18 changes: 13 additions & 5 deletions app/controllers/admin/categories_controller.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
class Admin::CategoriesController < Admin::BaseController
cache_sweeper :blog_sweeper

def index; redirect_to :action => 'new' ; end
def index
redirect_to :action => 'new' ;

Choose a reason for hiding this comment

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

If you refactor this code to be more than one line, then you should no longer use semi-colons

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 +28,17 @@ def destroy

def new_or_edit
@categories = Category.find(:all)
@category = Category.find(params[:id])
#@category = Category.find(params[:id])
if @category_id == nil

Choose a reason for hiding this comment

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

where is @category_id coming from?

Copy link
Author

Choose a reason for hiding this comment

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

I originally had @category.id, but changed it in response to an error message that said I should use object_id instead of object.id

Copy link
Author

Choose a reason for hiding this comment

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

I don't completely understand why it works, so I will refactor

@category = Category.new
else
@category = 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
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/grouping_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def render_articles
end

render active_template

end

format.atom { render_feed 'atom', @articles }
Expand All @@ -130,7 +130,7 @@ def set_noindex page = nil
return 1 if (grouping_class.to_s.downcase == "category" and this_blog.unindex_categories)
return 1 unless page.blank?
end

def active_template
return params[:id] if template_exists? "#{self.class.to_s.sub(/Controller$/,'').downcase}/#{params[:id]}"
return 'show' if template_exists? "#{self.class.to_s.sub(/Controller$/,'').downcase}/show"
Expand Down
6 changes: 3 additions & 3 deletions app/views/admin/categories/new.html.erb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<% @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 %>
<%= error_messages_for 'category' %>
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/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
resources :categories, :except => [:show, :update, :destroy, :edit]
resources :categories, :path => 'category', :only => [:show, :edit, :update, :destroy]
match '/category/:id/page/:page', :to => 'categories#show', :format => false


# TagsController (imitate inflected_resource)
resources :tags, :except => [:show, :update, :destroy, :edit]
Expand Down
17 changes: 17 additions & 0 deletions features/add_category.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Feature: Add Category
In order to maintain typo blog
As an admin
I want to add new categories

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

Scenario: Successfully Add Categories

Choose a reason for hiding this comment

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

This scenario looks good!

Given I am on the new category page
When I fill in "category_name" with "Sprinkles"
And I fill in "category_keywords" with "FoodStuffs"
And I fill in "category_description" with "Tasty on everything"
And I press "Save"
When I go to a list of categories
Then I should see "Sprinkles"
21 changes: 21 additions & 0 deletions features/edit_category.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Feature: Edit Category
In order to maintain typo blog
As an admin
I want to edit existing categories

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

Scenario: Successfully Edit Categories
Given I have categories named Fluffy, Shiny

Choose a reason for hiding this comment

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

It seems like this scenario with two different categories is adding extra steps. Since you are testing the edit functionality, i would start with only one category like Fluffy, and remove the extra steps related to Shiny.

When I go to a list of categories
Then I should see "Fluffy"
And I should see "Shiny"
When I go to edit Fluffy
When I fill in "category_name" with "SuperFluffy"
And I press "Save"
When I go to a list of categories
Then I should not see "Fluffy"
And I should see "SuperFluffy"
And I should see "Shiny"
14 changes: 14 additions & 0 deletions features/manage_category.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Feature: Manage Category
In order to maintain typo blog
As an admin
I want to view and manage categories

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

Scenario: Categories List
Given I have categories named Pizza, Breadsticks
When I go to a list of categories
Then I should see "Pizza"
And I should see "Breadsticks"
5 changes: 5 additions & 0 deletions features/step_definitions/category_steps.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Given /^I have categories named(.+)$/ do |names|
names.split(', ').each do |name|
Category.create!(:name => name)
end
end
6 changes: 3 additions & 3 deletions features/step_definitions/web_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,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 +264,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
5 changes: 5 additions & 0 deletions features/support/paths.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ def path_to(page_name)
when /^the new article page$/
'/admin/content/new'

when /a list of categories/
admin_categories_path

when /^the new category page$/
admin_categories_path
# 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