Skip to content
Browse files

adds integration testing for posting a blog piece

  • Loading branch information...
1 parent 0d8fc8a commit e156268ba73d7389bd683130579036507e46a4e0 @ZimChi ZimChi committed Mar 13, 2012
View
4 app/models/post.rb
@@ -28,6 +28,10 @@ def permalink_attributes
}
end
+ def get_permalink
+ self.permalink
+ end
+
@btaitelb
Coshx Labs member
btaitelb added a note Mar 13, 2012

This reminds me of java. Why do we need a get_permalink method if we can just access Post#permalink?

@ZimChi
ZimChi added a note Mar 14, 2012

yep, that's exactly what it is too. A java getter to access a private variable. I'm taking this out because this is ruby not java

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
def self.build_permalink(params)
"#{params[:year]}/#{params[:month]}/#{params[:day]}/#{params[:title]}"
end
View
43 features/admindashboard.feature
@@ -0,0 +1,43 @@
+
@btaitelb
Coshx Labs member
btaitelb added a note Mar 13, 2012

not a big deal, but the ruby naming convention is to use underscores (_) to separate words, so this should probably be admin_dashboard.feature

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+Feature: Admin Dashboard functionality
+
+ Background:
+ Given required data exists
+
+ Scenario: Admin signs in and makes a blog post
+ Given go to the sign in page
+ Then I should see "Sign in"
+ When I fill in "admin_email" with "testuser_1@coshx.com"
+ And I fill in "admin_password" with "password_1"
+ When I press "Sign in"
+ Then I should be on the dashboard page
+ And I should see "Admin Dashboard"
+ When I follow "New Blog Post"
+ Then I should be on the new blog post page
+ And I should see "New Blog Post"
+ When I fill in "post_title" with "post title"
+ And I fill in "post_body" with "post body"
+ And I press "Save"
+ Then I should be on the dashboard page
+ When I go to the blogs page
+ Then I should see "Blog"
+ And I should see "post title"
+ When I follow "post title"
+ Then I should be on the "post title" blog page
+ When I go to the blogs page
+ And I follow "Edit"
+ Then I should be on the "post title" blog edit page
+ When I fill in "post_title" with "post title2"
+ And I press "Save"
+ Then I should be on the "post title2" blog page
+ When I go to the blogs page
+ And I follow "Publish"
+ Then I should be on the "post title2" published blog page
+ When I go to the blogs page
+ Then I should see "post title2"
+ And I should not see "Publish"
+ When I follow "Read More"
+ Then I should be on the "post title2" published blog page
+
+
+
View
18 features/step_definitions/custom_steps.rb
@@ -0,0 +1,18 @@
+
+Given /^required data exists$/ do
@btaitelb
Coshx Labs member
btaitelb added a note Mar 13, 2012

Can you be more descriptive in this step definition? I can't tell from reading a feature file what should/shouldn't be required, so I think it's too much of a cop out.

@ZimChi
ZimChi added a note Mar 14, 2012

I agree - better to be more descriptive.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ Factory.create(:admin)
+end
+
+
+When(/^I go back$/) do
+ page.evaluate_script('window.history.back()')
+end
+
+Given /^I have a valid but expired token$/ do
+ Factory.create(:token,:id=>'3',:code =>'EFGH5678', :start_date =>Time.now()-4.days, :expiration_date => Time.now()-2.days)
+end
+
+Given /^I have a valid token$/ do
+ Factory.create(:token, :id=>'2',:campaign_id=>'1', :merchant_id => '1',:amount => '5.0',:code =>'IJKL9101', :start_date =>Time.now()-2.days, :expiration_date => Time.now()+2.days)
+end
+
View
41 features/step_definitions/user_steps.rb
@@ -0,0 +1,41 @@
+
+Given /^no user exists with an email of "(.*)"$/ do |email|
@btaitelb
Coshx Labs member
btaitelb added a note Mar 13, 2012

This looks more like a Then than a Given

@ZimChi
ZimChi added a note Mar 14, 2012

This is actually from abolishcancer, I copied over the step definitions to get started.. This can probably be pulled out. And I can make the change to over in the abolishcancer code.

@ZimChi
ZimChi added a note Mar 14, 2012

Deleted

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ User.find(:first, :conditions => { :email => email }).should be_nil
+end
+
+Then /^I should be already signed in$/ do
+ step %{I should see "Admin Portal"}
+ step %{I should not see "Sign in"}
+end
+
+Then /^I sign out$/ do
+ visit('/users/sign_out')
+end
+
+Given /^I am logout$/ do
@btaitelb
Coshx Labs member
btaitelb added a note Mar 13, 2012

I am legend.

@ZimChi
ZimChi added a note Mar 14, 2012

very strange haha

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ step %{I sign out}
+end
+
+Given /^I am not logged in$/ do
+ step %{I sign out}
+end
+
+When /^I sign in as "(.*)\/(.*)"$/ do |email, password|
+ step %{I am not logged in}
+ step %{I go to the sign in page}
+ step %{I fill in "Email" with "#{email}"}
+ step %{I fill in "Password" with "#{password}"}
+ step %{I press "Sign in"}
+end
+
+Then /^I should be signed in$/ do
+ step %{I should see "Admin Portal"}
+end
+
+When /^I return next time$/ do
+ step %{I go to the home page}
+end
+
+Then /^I should be signed out$/ do
+ step %{I should not see "Admin Portal"}
+end
View
220 features/step_definitions/web_steps.rb
@@ -0,0 +1,220 @@
+# IMPORTANT: This file is generated by cucumber-rails - edit at your own peril.
+# It is recommended to regenerate this file in the future when you upgrade to a
+# newer version of cucumber-rails. Consider adding your own code to a new file
+# instead of editing this one. Cucumber will automatically load all features/**/*.rb
+# files.
+
+
+require 'uri'
+require 'cgi'
+require File.expand_path(File.join(File.dirname(__FILE__), "..", "support", "paths"))
+
+module WithinHelpers
+ def with_scope(locator)
+ locator ? within(locator) { yield } : yield
+ end
+end
+World(WithinHelpers)
+
+
+When /^(?:|I )am on (.+)$/ do |page_name|
+ visit path_to(page_name)
+end
+
+When /^(?:|I )go to (.+)$/ do |page_name|
+ visit path_to(page_name)
+end
+
+When /^(?:|I )press "([^"]*)"(?: within "([^"]*)")?$/ do |button, selector|
+ with_scope(selector) do
+ click_button(button)
+ end
+end
+
+When /^(?:|I )follow "([^"]*)"(?: within "([^"]*)")?$/ do |link, selector|
+ with_scope(selector) do
+ click_link(link)
+ end
+end
+
+When /^(?:|I )fill in "([^"]*)" with "([^"]*)"(?: within "([^"]*)")?$/ do |field, value, selector|
+ with_scope(selector) do
+ fill_in(field, :with => value)
+ end
+end
+
+When /^(?:|I )fill in "([^"]*)" for "([^"]*)"(?: within "([^"]*)")?$/ do |value, field, selector|
+ with_scope(selector) do
+ fill_in(field, :with => value)
+ end
+end
+
+# Use this to fill in an entire form with data from a table. Example:
+#
+# When I fill in the following:
+# | Account Number | 5002 |
+# | Expiry date | 2009-11-01 |
+# | Note | Nice guy |
+# | Wants Email? | |
+#
+# TODO: Add support for checkbox, select og option
+# based on naming conventions.
+#
+When /^(?:|I )fill in the following(?: within "([^"]*)")?:$/ do |selector, fields|
+ with_scope(selector) do
+ fields.rows_hash.each do |name, value|
+ When %{I fill in "#{name}" with "#{value}"}
+ end
+ end
+end
+
+When /^(?:|I )select "([^"]*)" from "([^"]*)"(?: within "([^"]*)")?$/ do |value, field, selector|
+ with_scope(selector) do
+ select(value, :from => field)
+ end
+end
+
+When /^(?:|I )check "([^"]*)"(?: within "([^"]*)")?$/ do |field, selector|
+ with_scope(selector) do
+ check(field)
+ end
+end
+
+When /^(?:|I )uncheck "([^"]*)"(?: within "([^"]*)")?$/ do |field, selector|
+ with_scope(selector) do
+ uncheck(field)
+ end
+end
+
+When /^(?:|I )choose "([^"]*)"(?: within "([^"]*)")?$/ do |field, selector|
+ with_scope(selector) do
+ choose(field)
+ end
+end
+
+When /^(?:|I )attach the file "([^"]*)" to "([^"]*)"(?: within "([^"]*)")?$/ do |path, field, selector|
+ with_scope(selector) do
+ attach_file(field, path)
+ end
+end
+
+Then /^(?:|I )should see JSON:$/ do |expected_json|
+ require 'json'
+ expected = JSON.pretty_generate(JSON.parse(expected_json))
+ actual = JSON.pretty_generate(JSON.parse(response.body))
+ expected.should == actual
+end
+
+Then /^(?:|I )should see "([^"]*)"(?: within "([^"]*)")?$/ do |text, selector|
+ with_scope(selector) do
+ if page.respond_to? :should
+ page.should have_content(text)
+ else
+ assert page.has_content?(text)
+ end
+ end
+end
+
+Then /^(?:|I )should see \/([^\/]*)\/(?: within "([^"]*)")?$/ do |regexp, selector|
+ regexp = Regexp.new(regexp)
+ with_scope(selector) do
+ if page.respond_to? :should
+ page.should have_xpath('//*', :text => regexp)
+ else
+ assert page.has_xpath?('//*', :text => regexp)
+ end
+ end
+end
+
+Then /^(?:|I )should not see "([^"]*)"(?: within "([^"]*)")?$/ do |text, selector|
+ with_scope(selector) do
+ if page.respond_to? :should
+ page.should have_no_content(text)
+ else
+ assert page.has_no_content?(text)
+ end
+ end
+end
+
+Then /^(?:|I )should not see \/([^\/]*)\/(?: within "([^"]*)")?$/ do |regexp, selector|
+ regexp = Regexp.new(regexp)
+ with_scope(selector) do
+ if page.respond_to? :should
+ page.should have_no_xpath('//*', :text => regexp)
+ else
+ assert page.has_no_xpath?('//*', :text => regexp)
+ end
+ end
+end
+
+Then /^the "([^"]*)" field(?: within "([^"]*)")? should contain "([^"]*)"$/ do |field, selector, value|
+ with_scope(selector) do
+ field = find_field(field)
+ field_value = (field.tag_name == 'textarea') ? field.text : field.value
+ if field_value.respond_to? :should
+ field_value.should =~ /#{value}/
+ else
+ assert_match(/#{value}/, field_value)
+ end
+ end
+end
+
+Then /^the "([^"]*)" field(?: within "([^"]*)")? should not contain "([^"]*)"$/ do |field, selector, value|
+ with_scope(selector) do
+ field = find_field(field)
+ field_value = (field.tag_name == 'textarea') ? field.text : field.value
+ if field_value.respond_to? :should_not
+ field_value.should_not =~ /#{value}/
+ else
+ assert_no_match(/#{value}/, field_value)
+ end
+ end
+end
+
+Then /^the "([^"]*)" checkbox(?: within "([^"]*)")? should be checked$/ do |label, selector|
+ with_scope(selector) do
+ field_checked = find_field(label)['checked']
+ if field_checked.respond_to? :should
+ field_checked.should be_true
+ else
+ assert field_checked
+ end
+ end
+end
+
+Then /^the "([^"]*)" checkbox(?: within "([^"]*)")? should not be checked$/ do |label, selector|
+ with_scope(selector) do
+ field_checked = find_field(label)['checked']
+ if field_checked.respond_to? :should
+ field_checked.should be_false
+ else
+ assert !field_checked
+ end
+ end
+end
+
+Then /^(?:|I )should be on (.+)$/ do |page_name|
+ current_path = URI.parse(current_url).path
+ if current_path.respond_to? :should
+ current_path.should == path_to(page_name)
+ else
+ assert_equal path_to(page_name), current_path
+ end
+end
+
+Then /^(?:|I )should have the following query string:$/ do |expected_pairs|
+ 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(',')}
+
+ if actual_params.respond_to? :should
+ actual_params.should == expected_params
+ else
+ assert_equal expected_params, actual_params
+ end
+end
+
+Then /^show me the page$/ do
+ save_and_open_page
+end
View
63 features/support/paths.rb
@@ -0,0 +1,63 @@
+module NavigationHelpers
+ # Maps a name to a path. Used by the
+ #
+ # When /^I go to (.+)$/ do |page_name|
+ #
+ # step definition in web_steps.rb
+ #
+ def path_to(page_name)
+ case page_name
+
+ when /the home\s?page/
+ '/'
+
+ when /the sign in page/
+ '/admins/sign_in'
+
+ when /the dashboard page/
+ '/dashboard'
+
+ when /the new blog post page/
+ '/posts/new'
+
+ when /the new job post page/
+ '/careers/new'
+
+ when /the blogs page/
+ '/blog'
+
+ when /the children list page for "(.+)"/
+ p = Parent.find_by_name($1)
+ parent_children_path(p)
+
+ when /the "(.+)" blog page/
+ "/posts/#{Post.find_by_title($1).id}"
+
+ when /the "(.+)" blog edit page/
+ "/posts/#{Post.find_by_title($1).id}/edit"
+
+ when /the "(.+)" published blog page/
+ "/blog/#{Post.find_by_title($1).get_permalink}"
+
+
+
+ # Add more mappings here.
+ # Here is an example that pulls values out of the Regexp:
+ #
+ # when /^(.*)'s profile page$/i
+ # user_profile_path(User.find_by_login($1))
+
+ else
+ begin
+ page_name =~ /the (.*) page/
+ path_components = $1.split(/\s+/)
+ self.send(path_components.push('path').join('_').to_sym)
+ rescue Object => e
+ raise "Can't find mapping from \"#{page_name}\" to a path.\n" +
+ "Now, go and add a mapping in #{__FILE__}"
+ end
+ end
+ end
+end
+
+World(NavigationHelpers)

0 comments on commit e156268

Please sign in to comment.
Something went wrong with that request. Please try again.