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

New Feature Scenario 1 Semi-Complete #27

Open
wants to merge 25 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
1a394c6
Cucumber tests for category bug
knaydee Mar 29, 2016
04dee87
Add pry gem
knaydee Mar 29, 2016
2d27732
Update paths for admin page
knaydee Mar 29, 2016
d7825ec
fix new or edit method using case - where if id is nill create a new …
knaydee Mar 29, 2016
a58edb8
working cucumber tests for clicking Categories link on admin panel
knaydee Mar 29, 2016
caede3b
passing rspec test for clicking on categories link on admin panel
knaydee Mar 29, 2016
ba17a52
cucumber test for creating a new category
knaydee Mar 29, 2016
6bfd744
cucumber test to check if category count increases by 1 when new cate…
knaydee Mar 29, 2016
2119aa1
modify cucumber category scenario to test edit
knaydee Mar 29, 2016
72f97da
modify category new rspec
knaydee Mar 29, 2016
50f9816
modify new category rspec
knaydee Mar 29, 2016
4608971
Edits made to categories controller spec and web steps suggested by Kari
knaydee Mar 29, 2016
074dd6c
cucumber test for not admin
knaydee Mar 30, 2016
0545fd9
cucumber test for not admin and on the new article page
knaydee Mar 30, 2016
2e9314e
cucumber test that non admins should not see merge_with field
knaydee Mar 30, 2016
5094111
cucumber scenario passes when admin is logged in and cannot see merge…
knaydee Mar 30, 2016
6380488
cucumber scenario for admin being able to see merge field, need to ad…
knaydee Mar 30, 2016
f5e254d
non admins are not allowed to edit - scenario passes
knaydee Mar 30, 2016
edeef0c
merge articles does not show on new article page - scenario passes
knaydee Mar 30, 2016
7f5f30e
scenarios written for seeing merge articles on edit article page as a…
knaydee Mar 30, 2016
2b63436
remove scenario for merge articles on edit page as it was a duplicate
knaydee Mar 30, 2016
4dbe73d
Test text that only shows when an admin user is logged in
knaydee Mar 30, 2016
0598dc2
scenarios that I thought were testing what I wanted tested are fixed …
knaydee Mar 30, 2016
deccf7e
text 'Merge Articles' only shows up on edit view for admins only, all…
knaydee Mar 30, 2016
732bcef
category edit page path
knaydee 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 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
13 changes: 9 additions & 4 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,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
Expand Down
13 changes: 9 additions & 4 deletions app/views/admin/content/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<div class='clearfix'>
<%= _("Status:") %> <strong><%= @article.state.to_s.downcase %></strong> <a href="#" onclick="Element.toggle('status'); return false">Change</a>
<ul class='inputs-list'>
<li id='status' style='display: none;'>
<li id='status' style='display: none;'>
<label for="article_published">
<%= check_box 'article', 'published' %>
<%= _("Published") %>
Expand Down Expand Up @@ -129,7 +129,7 @@
<div class='class'>
<%= text_field 'article', 'keywords', {:autocomplete => 'off', :style => 'width: 100%'} %>
</div>
<%= auto_complete_field 'article_keywords', { :url => { :action => "auto_complete_for_article_keywords"}, :tokens => ','}%>
<%= auto_complete_field 'article_keywords', { :url => { :action => "auto_complete_for_article_keywords"}, :tokens => ','}%>
</div>

<div class='separator'>
Expand All @@ -146,8 +146,13 @@
<ul id='attachments' class='inputs-list'>
<%= render 'admin/content/attachment', { :attachment_num => 1, :hidden => false } -%>
</ul>
</div>
</div>
<% if current_user.admin? && @article.title != nil %>
<h4>Merge Articles</h4>
<!-- <p>
put Article ID field here and Merge Button for edit form only
</p> -->
<% end %>
</div>

</div>

13 changes: 13 additions & 0 deletions features/manage_articles.feature
Original file line number Diff line number Diff line change
@@ -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

Choose a reason for hiding this comment

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

This feature is in-progess/copy-paste from the categories one, correct?

Given I am on the admin page
When I follow "Categories"
Then I should be on the new or edit category page
23 changes: 23 additions & 0 deletions features/manage_categories.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Feature: Manage Categories

Choose a reason for hiding this comment

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

These scenarios are nicely set up

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"
26 changes: 26 additions & 0 deletions features/merge_articles.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
Feature: Merge articles

Choose a reason for hiding this comment

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

These scenarios are nicely set up. What do you think you'd want to add once the merge was fully implemented?

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"
38 changes: 35 additions & 3 deletions features/step_definitions/web_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ def with_scope(locator)
:profile_id => 1,
:name => 'admin',
:state => 'active'})
User.create!({:login => 'not admin',
:password => 'bbbbb',
:email => '[email protected]',
:profile_id => 2,
:name => 'not admin',
:state => 'active'})
end

And /^I am logged into the admin panel$/ do
Expand All @@ -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 }
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
11 changes: 11 additions & 0 deletions features/support/paths.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
16 changes: 14 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,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
Expand Down Expand Up @@ -48,7 +60,7 @@

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

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

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

end