Skip to content

Instantly share code, notes, and snippets.

@npverni
Created October 29, 2009 15:35
Show Gist options
  • Save npverni/221518 to your computer and use it in GitHub Desktop.
Save npverni/221518 to your computer and use it in GitHub Desktop.
boston.rb: Test, Feature and code for Jobs Atom Feed
From ec7bf4201c54d03d603b47452a5da98659e99b8b Mon Sep 17 00:00:00 2001
From: Nathan Verni <npverni@gmail.com>
Date: Thu, 29 Oct 2009 11:28:05 -0400
Subject: [PATCH 1/2] Test, Feature and code for Jobs Atom Feed
---
app/views/jobs/index.atom.builder | 19 +++++++++++++++++++
1 files changed, 19 insertions(+), 0 deletions(-)
create mode 100644 app/views/jobs/index.atom.builder
diff --git a/app/views/jobs/index.atom.builder b/app/views/jobs/index.atom.builder
new file mode 100644
index 0000000..bd3757c
--- /dev/null
+++ b/app/views/jobs/index.atom.builder
@@ -0,0 +1,19 @@
+atom_feed :schema_date => 2009 do |feed|
+ feed.title("Boston.rb Jobs")
+ feed.subtitle("Jobs for Boston Rubyists")
+ feed.updated(@jobs.first.updated_at) if @jobs.any?
+
+ @jobs.each do |job|
+ feed.entry(job) do |entry|
+ entry.title("#{job.title} at #{job.organization}")
+ entry.content "type" => "html" do
+ xml.text!("<strong>Location:</strong> #{job.location}")
+ xml.text!(job.cached_description_html)
+ end
+
+ entry.author do |author|
+ author.name("Boston Ruby Group")
+ end
+ end
+ end
+end
--
1.6.4.2
From b4db2c3380101e667ba111e46689ab789647ad2b Mon Sep 17 00:00:00 2001
From: Nathan Verni <npverni@gmail.com>
Date: Thu, 29 Oct 2009 11:32:26 -0400
Subject: [PATCH 2/2] Test, Feature and code for Jobs Atom Feed
---
app/controllers/jobs_controller.rb | 2 ++
features/jobs.feature | 8 +++++++-
features/support/paths.rb | 3 ++-
test/functional/jobs_controller_test.rb | 21 +++++++++++++++++++++
4 files changed, 32 insertions(+), 2 deletions(-)
diff --git a/app/controllers/jobs_controller.rb b/app/controllers/jobs_controller.rb
index 1b2c86d..bfa6767 100644
--- a/app/controllers/jobs_controller.rb
+++ b/app/controllers/jobs_controller.rb
@@ -3,6 +3,8 @@ class JobsController < InheritedResources::Base
before_filter :authorize, :only => [:edit]
+ respond_to :atom, :only => :index
+
def create
create! { root_url }
end
diff --git a/features/jobs.feature b/features/jobs.feature
index aa85a69..77effca 100644
--- a/features/jobs.feature
+++ b/features/jobs.feature
@@ -25,4 +25,10 @@ Feature: Jobs
And I follow "This is a job"
Then I should see "This is a job at thoughtbot"
And I should see "user interface to the metal - you should love doing it all."
-
\ No newline at end of file
+
+ Scenario: Viewing jobs atom feed
+ Given a job exists with a title of "This is a job"
+ And a job exists with a title of "Here is another cool job"
+ When I go to the jobs atom feed
+ Then I should see "This is a job at thoughtbot"
+ And I should see an entry for "Here is another cool job at thoughtbot"
diff --git a/features/support/paths.rb b/features/support/paths.rb
index a75c8da..7204b1d 100644
--- a/features/support/paths.rb
+++ b/features/support/paths.rb
@@ -20,7 +20,8 @@ module NavigationHelpers
presentation_path(@presentation)
when /new presentation page/i
new_presentation_path
-
+ when /the jobs atom feed/i
+ jobs_path :format => :atom
# Add more page name => path mappings here
else
diff --git a/test/functional/jobs_controller_test.rb b/test/functional/jobs_controller_test.rb
index 879b647..dcb6f8e 100644
--- a/test/functional/jobs_controller_test.rb
+++ b/test/functional/jobs_controller_test.rb
@@ -54,6 +54,27 @@ class JobsControllerTest < ActionController::TestCase
should_redirect_to("home") { root_path }
end
+ context "on GET to /jobs :format => 'atom' with jobs" do
+ setup do
+ Factory(:job)
+ get :index, :format => 'atom'
+ end
+
+ should_assign_to :jobs
+ should_render_template 'index.atom'
+ should_respond_with :success
+ end
+
+ context "on GET to /jobs :format => 'atom' without jobs" do
+ setup do
+ get :index, :format => 'atom'
+ end
+
+ should_assign_to :jobs
+ should_render_template 'index.atom'
+ should_respond_with :success
+ end
+
context 'on PUT to /jobs/:id when signed in' do
setup do
sign_in
--
1.6.4.2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment