Skip to content

Commit

Permalink
Fixing tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
futurechimp committed Jun 16, 2011
1 parent 9faf54b commit b01a918
Show file tree
Hide file tree
Showing 9 changed files with 134 additions and 87 deletions.
2 changes: 1 addition & 1 deletion admin/views/feeds/_form.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<div class="group">
<%= f.label :wire %><%= f.error_message_on :wire %>
<%= f.select :wire_id, :collection => @wires, :fields => [:name, :id] %>
<%= f.select :wire, :collection => @wires, :fields => [:name, :id] %>
<span class="description">Please choose a wire.</span>
</div>

Expand Down
126 changes: 53 additions & 73 deletions test/app/controllers/admin/feeds_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,93 +4,73 @@
class Admin::FeedsControllerTest < Test::Unit::TestCase
context "Admin::FeedsController" do

context "on GET to index" do
setup do
Account.delete_all
end

context "when logged in" do
setup do
FeedItem.destroy_all
@feed_item = FeedItem.make
@feed_item.save
get '/admin/feeds'
@account = Factory.make_admin
login_as(@account)
end

context "on GET to index" do
setup do
FeedItem.destroy_all
@feed_item = FeedItem.make
@feed_item.save
get '/admin/feeds'
end

should "work" do
assert last_response.ok?
end
should "work" do
assert last_response.ok?
end

should "display the url of @feed_item" do
assert_match @feed_item.url, last_response.body
should "display the url of @feed_item" do
assert_match @feed_item.url, last_response.body
end
end
end

context "on GET to new" do
setup do
@wire = Wire.make
@wire.save
get '/admin/feeds/new'
end
context "on GET to new" do
setup do
@wire = Wire.make
@wire.save
get '/admin/feeds/new'
end

should "work" do
assert last_response.ok?
assert_match /New/, last_response.body
end

should "insert the @wire name into the body" do
assert last_response.body.include?(@wire.name)
end
end
should "work" do
assert last_response.ok?
assert_match /New/, last_response.body
end

context "on GET to edit" do
setup do
@wire = Wire.make
@wire.save
@feed = Factory.make_stubbed_feed
@feed.save
get "/admin/feeds/edit/#{@feed.id}"
should "insert the @wire name into the body" do
assert last_response.body.include?(@wire.name)
end
end

should "work" do
assert last_response.ok?
assert_match /#{@feed.url}/, last_response.body
end

should "insert the @wire name into the body" do
assert last_response.body.include?(@wire.name)
end

end
context "on GET to edit" do
setup do
@wire = Wire.make
@wire.save
@feed = Factory.make_stubbed_feed
@feed.save
get "/admin/feeds/edit/#{@feed.id}"
end

context "on POST to notify" do
context "with good params" do
context "on an empty feed" do
setup do
@feed = Factory.make_stubbed_feed
@wire = Wire.make
@wire.save
@feed.wire = @wire
@feed.save
@original_feed_item_count = FeedItem.count
@feed_length = FeedNormalizer::FeedNormalizer.parse(
good_feed_content).entries.length
post "/admin/feeds/notify/#{@feed.to_param}",
:data => good_feed_content
end

should "work" do
assert last_response.ok?
end

should "respond with success message" do
assert_equal(last_response.body, "success")
end

should_eventually "add as many feed_items as are in the feed" do
assert_equal(
@original_feed_item_count + @feed_length, FeedItem.count
)
end
should "work" do
assert last_response.ok?
assert_match /#{@feed.url}/, last_response.body
end
end

should "insert the @wire name into the body" do
assert last_response.body.include?(@wire.name)
end

end
end



# context "with an existing feed but bad feed body content" do
#
# end
Expand Down
8 changes: 4 additions & 4 deletions test/app/controllers/home_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ class HomeControllerTest < Test::Unit::TestCase
assert last_response.ok?
end

should "have the 'labs' title in the layout" do
assert_match "Labs", last_response.body
should "have the 'aggro' title in the layout" do
assert_match "Aggro", last_response.body
end
end

Expand All @@ -32,8 +32,8 @@ class HomeControllerTest < Test::Unit::TestCase
assert last_response.ok?
end

should "have the 'labs' title in the layout" do
assert_match "Labs", last_response.body
should "have the 'aggro' title in the layout" do
assert_match "Aggro", last_response.body
end

should "output the @feed_item title" do
Expand Down
57 changes: 52 additions & 5 deletions test/app/controllers/updates_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,59 @@

class UpdatesControllerTest < Test::Unit::TestCase
context "UpdatesController" do
setup do
get '/'
end

should "return hello world text" do
assert_equal "Hello World", last_response.body
context "on POST to notify" do
context "with good params" do
context "on an empty feed" do
setup do
@feed = Factory.make_stubbed_feed
@wire = Wire.make
@wire.save
@feed.wire = @wire
@feed.save
@original_feed_item_count = FeedItem.count
@feed_length = FeedNormalizer::FeedNormalizer.parse(
good_feed_content).entries.length
post "/updates/notify/#{@feed.to_param}",
:data => good_feed_content
end

should "work" do
assert last_response.ok?
end

should "respond with success message" do
assert_equal("success", last_response.body)
end

should_eventually "add as many feed_items as are in the feed" do
assert_equal(
@original_feed_item_count + @feed_length, FeedItem.count
)
end
end

context "when the user decides to change the @feed#wire" do
setup do
@feed = Factory.make_stubbed_feed
@wire = Wire.make
@wire.save
@feed.wire = @wire
@feed.save
@other_wire = Wire.make
@other_wire.save
post "/updates/notify/#{@feed.to_param}",
:data => {:wire_id => @other_wire.id }
@feed.reload
end

should "update the @feed's wire properly" do
assert_equal(@wire, @feed.wire)
end
end

end
end

end
end
2 changes: 1 addition & 1 deletion test/app/models/feed_item_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ class FeedItemTest < Test::Unit::TestCase

context "with no image attached" do
setup do
stub_request(:any, "http://admin:admin@octopus:2001/create")
stub_request(:any, "http://admin:admin@localhost:2001/create")
@feed_item = FeedItem.make(:with_feed_and_wire)
@feed_item.feed.image = File.new(
PADRINO_ROOT + "/test/fixtures/omegaman.jpg")
Expand Down
4 changes: 4 additions & 0 deletions test/app/models/feed_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ class FeedTest < Test::Unit::TestCase
good_feed_content).items.length, @feed.feed_items.length)
end
end

context "updating when an item in the feed has no content" do
should "work"
end
end

# context "for a feed which includes images in its item descriptions" do
Expand Down
9 changes: 9 additions & 0 deletions test/blueprints.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
Account.blueprint do
name
email
password { "password" }
password_confirmation { "password" }
role { "user" }
end

Feed.blueprint do
Expand Down Expand Up @@ -50,6 +53,12 @@ class << self
include TestHelper::StubbedOctopusCalls
include WebMock

def make_admin
account = Account.make(:role => "admin")
account.save!
account
end

# Returns a Feed object with a pseudo-random uuid as its id. We use the
# bullshit_uuid because Machinist doesn't set an id on the new feed object
# in feed = Feed.make, and we need the feed.id to stub successful net
Expand Down
4 changes: 2 additions & 2 deletions test/support/stubbed_octopus_calls.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ def successful_subscription_request_body(feed)
{
:body => {
:net_resource => {:url => feed.url},
:subscription => {:url => "#{::SERVER_URL}/admin/feeds/notify/#{feed.id}"}
:subscription => {:url => "#{::SERVER_URL}/updates/notify/#{feed.id}"}
}}
end

def subscription_url
"http://admin:admin@octopus:2001/create"
"http://admin:admin@localhost:2001/create"
end

def good_feed_content
Expand Down
9 changes: 8 additions & 1 deletion test/test_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Test::Unit::TestCase
include TestHelper::StubbedOctopusCalls
include TestHelper::StubbedWebRequests

WebMock.disable_net_connect!(:allow_localhost => true)
WebMock.disable_net_connect!

def app
##
Expand All @@ -39,6 +39,13 @@ def small_feed_item_image
File.dirname(__FILE__) + "/fixtures/tiny.png"
)
end

def login_as(account)
post "/admin/sessions/create", {
:email => account.email, :password => "password"
}
follow_redirect!
end


end

0 comments on commit b01a918

Please sign in to comment.