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

Bug Fix and Feature Added #17

Open
wants to merge 47 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
08d1c63
initial typo setup
kedevlin Mar 28, 2016
43e55a3
add db/db_test to gitignore
kedevlin Mar 28, 2016
48eeb14
fixed untracked files
kedevlin Mar 28, 2016
7fc0ddd
added cucumber test for clicking category link
kedevlin Mar 28, 2016
ccfbc0e
create failing rspec test for bug
kedevlin Mar 28, 2016
cfe2496
add pry to gemfile, fix bug so tests pass
kedevlin Mar 28, 2016
f73ad31
add test for post edit
kedevlin Mar 28, 2016
c0ffdf4
create rspec and cucumber test for handling a new category with no name
kedevlin Mar 29, 2016
53d9920
cucumber test passes, need to fix rspec test
kedevlin Mar 29, 2016
2c19f06
fixed rspec test for bad params, checked that it fails when original …
kedevlin Mar 29, 2016
716395c
create failing cucumber test for unique name requirement
kedevlin Mar 29, 2016
0a83ce6
create failing rspec tests for unique name requirement
kedevlin Mar 29, 2016
db76e89
fixed bug for handling duplicate category name
kedevlin Mar 29, 2016
17aba9f
create failing test for editing a category with a duplicate name
kedevlin Mar 29, 2016
4a47d2c
add failing rspec test for changing name to duplicate
kedevlin Mar 29, 2016
796a6c9
removed tests validating uniqueness of name on edit; based on model v…
kedevlin Mar 29, 2016
0a9b276
remove require pry, move pry gem to pre-exisitng dev-test group
kedevlin Mar 29, 2016
0e02649
utilize the save method without the bang in conditional
kedevlin Mar 29, 2016
5e047aa
remove bin/ from git ignore, add db/db_development to gitignore
kedevlin Mar 29, 2016
106f474
create new feature file and create first scenario
kedevlin Mar 29, 2016
f00576f
add cucumber test for showing form to non-admin users
kedevlin Mar 29, 2016
61a23e8
add merge form, route, and controller method
kedevlin Mar 29, 2016
9bd79e1
cannot view merge form on new articles
kedevlin Mar 29, 2016
7d11ec6
change article id field id to merge_with per requirements
kedevlin Mar 29, 2016
e3ad079
remove @new variable from controller
kedevlin Mar 29, 2016
888fa03
add cucumber test for merging two articles as an admin
kedevlin Mar 30, 2016
8032860
add cucumber test for merging articles when one does not exist
kedevlin Mar 30, 2016
92bc841
add cucumber test for merging article with itself
kedevlin Mar 30, 2016
3c9be19
add cucumber tests for feature scenarios
kedevlin Mar 30, 2016
3c30118
create skeleton of specs
kedevlin Mar 30, 2016
7ce1069
create merge_with method and skeleton specs for model and controller
kedevlin Mar 30, 2016
a55b0f1
create failing rspec tests for good params and skeleton for bad params
kedevlin Mar 30, 2016
0ce609b
failing tests for bad params with merge
kedevlin Mar 30, 2016
26afd55
update skeleton of model tests
kedevlin Mar 30, 2016
5c13eb8
create article model rspec tests
kedevlin Mar 30, 2016
720ba06
add tests for functionality when article does not exist or same article
kedevlin Mar 30, 2016
2bf626f
merge_with method returns nil if article doesn't exist or it's the sa…
kedevlin Mar 30, 2016
0aac034
create new article in merge_with method
kedevlin Mar 30, 2016
aad6af0
update article count test
kedevlin Mar 30, 2016
b60a687
transfer comments to new article
kedevlin Mar 30, 2016
673b158
destroy original articles, fix artic spec testing change in Article c…
kedevlin Mar 30, 2016
afb8046
update before action for controller spec, add model method call in co…
kedevlin Mar 30, 2016
b4e5cba
change flash tests to be_present
kedevlin Mar 30, 2016
88a8f66
confirm user is admin before merge method
kedevlin Mar 30, 2016
2e2660b
error message displays, unable to get specs to pass
kedevlin Mar 30, 2016
9b74812
update cucumber tests based on actual flash error message
kedevlin Mar 30, 2016
80cc199
remove notice for successful merge from test
kedevlin Mar 30, 2016
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 .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ config/mail.yml
*~
db/*.sqlite*
db/schema.rb
db/db_test
.*.swp
.*.swo
.DS_Store
Expand Down
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ dbfile = File.expand_path("../config/database.yml", __FILE__)
# end
#end

gem 'pry-nav', group: [:development, :test]

Choose a reason for hiding this comment

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

Is there an existing development, test group that this gem should be added to?

Copy link
Author

Choose a reason for hiding this comment

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

moved to pre-existing group.


group :production do
gem 'pg'
end
Expand Down
19 changes: 18 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,22 @@ 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)
pry-nav (0.0.4)
pry (~> 0.9.7.4)
rack (1.2.5)
rack-mount (0.6.14)
rack (>= 1.0.0)
Expand Down Expand Up @@ -141,17 +150,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 +206,7 @@ DEPENDENCIES
kaminari
mini_magick (~> 1.3.3)
pg
pry-nav
rails (~> 3.0.10)
rake (~> 0.9.2)
recaptcha
Expand All @@ -205,3 +219,6 @@ DEPENDENCIES
thin
uuidtools (~> 2.1.1)
webrat

BUNDLED WITH
1.11.2
17 changes: 11 additions & 6 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 commits with pry!

Copy link
Author

Choose a reason for hiding this comment

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

removed

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,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(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 @@ -43,12 +48,12 @@ def new_or_edit
end

def save_category
if @category.save!
@category.save
if @category.errors.empty?

Choose a reason for hiding this comment

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

You can also utilize the save method without the bang in this conditional which should give you the same result

Copy link
Author

Choose a reason for hiding this comment

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

updated

flash[:notice] = _('Category was successfully saved.')
else
flash[:error] = _('Category could not be saved.')
end
redirect_to :action => 'new'
end

end
1 change: 0 additions & 1 deletion app/models/category.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,3 @@ def set_permalink
validates_presence_of :name
validates_uniqueness_of :name, :on => :create
end

Binary file added db/db_development
Binary file not shown.
3 changes: 0 additions & 3 deletions db/schema.sqlite.sql

This file was deleted.

3 changes: 0 additions & 3 deletions db/schema.sqlite3.sql

This file was deleted.

25 changes: 25 additions & 0 deletions features/create_category.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Feature: Create Categories
As a blog administrator
In order to categorize my articles
I want to be able to create new categories

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

Scenario: View Categories Page
Given I am on the admin dashboard page
When I follow "Categories"
Then I should see "Categories"

Scenario: Create New Category Requires Name
Given I am on the admin categories page
When I press "Save"
Then I should see "Category could not be saved."

Scenario: Create New Category Requires Unique Name
Given I am on the admin categories page
And a category named "test" already exists
When I enter "test" into the "category_name" input field
And I press "Save"
Then I should see "Category could not be saved."
14 changes: 11 additions & 3 deletions features/step_definitions/web_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ def with_scope(locator)
end
end

Given /^a category named "(.*?)" already exists$/ do |name|
Category.create!({:name => name})
end

When /^I enter "(.*?)" into the "(.*?)" input field$/ do |input, field|
fill_in(field, :with => input)
end

# Single-line step scoper
When /^(.*) within (.*[^:])$/ do |step, parent|
with_scope(parent) { When step }
Expand Down Expand Up @@ -250,7 +258,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 +272,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
54 changes: 52 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,56 @@
assert_response :redirect, :action => 'index'
end

describe "GET 'new'" do
it "is successful" do
get :new
expect(response.status).to eq 200
end
end

describe "POST 'edit'" do
context "good params" do
it "creates a new category" do
expect {
post :edit, {"category"=>{"name"=>"test"}}
}.to change(Category, :count).by(1)
end
end

context "no name" do
it "creates flash error" do
post :edit, {"category"=>{"name"=>""}}
expect(flash[:error]).to be_present
end

it "does not create a new category" do
expect {
post :edit, {"category"=>{"name"=>""}}
}.to change(Category, :count).by(0)
end
end

context "category with name already exists" do
before(:each) do
Category.create!({:name => "test"})
end

let(:category_2) {Category.create!({:name => "second category"})}

it "creates flash error for new categories" do
post :edit, {"category"=>{"name"=>"test"}}
expect(flash[:error]).to be_present
end

it "does not create a new category" do
expect {
post :edit, {"category"=>{"name"=>"test"}}
}.to change(Category, :count).by(0)
end
end

end

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

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

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

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

end
8 changes: 4 additions & 4 deletions spec/controllers/categories_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,14 @@ def do_get
do_get
response.should render_template('articles/index')
end

it 'should render personal when template exists' do
pending "Stubbing #template_exists is not enough to fool Rails"
controller.stub!(:template_exists?) \
.and_return(true)
do_get
response.should render_template('personal')
end
end

it 'should show only published articles' do
do_get
Expand All @@ -94,7 +94,7 @@ def do_get

describe "when rendered" do
render_views

it 'should have a canonical URL' do
do_get
response.should have_selector('head>link[href="http://myblog.net/category/personal/"]')
Expand Down Expand Up @@ -154,7 +154,7 @@ def do_get

assert_tag :tag => "input",
:attributes => { :id => "article_password" }
end
end
end

describe CategoriesController, "SEO Options" do
Expand Down
Loading