|
require 'wufoo' |
|
require 'test/unit' |
|
|
|
class WufooSessionTest < Test::Unit::TestCase |
|
def setup |
|
@session ||= Wufoo.login("things", "w00t") |
|
end |
|
|
|
def test_return_value |
|
assert @session.is_a?(Wufoo::Session) |
|
end |
|
|
|
def test_api_key |
|
assert_equal "w00t", @session.api_key |
|
end |
|
|
|
def test_subdomain |
|
assert_equal "things", @session.subdomain |
|
end |
|
|
|
def test_credentials |
|
creds = {:username => "w00t", :password => "n3rdZr00l"} |
|
assert_equal creds, @session.credentials |
|
end |
|
|
|
def test_base_url |
|
assert_equal "https://things.wufoo.com/api/v3/forms", (@session.base_url % "forms") |
|
end |
|
|
|
def test_users |
|
assert @session.users.is_a?(Wufoo::ResourceCollection) |
|
assert_equal Wufoo::User, @session.users.resource_class |
|
assert_nil @session.users.parent_path |
|
end |
|
|
|
def test_reports |
|
assert @session.reports.is_a?(Wufoo::ResourceCollection) |
|
assert_equal Wufoo::Report, @session.reports.resource_class |
|
assert_nil @session.reports.parent_path |
|
end |
|
|
|
def test_forms |
|
assert @session.forms.is_a?(Wufoo::ResourceCollection) |
|
assert_equal Wufoo::Form, @session.forms.resource_class |
|
assert_nil @session.forms.parent_path |
|
end |
|
end |
|
|
|
class StubResource |
|
class <<self |
|
def collection_path(parent_path) |
|
"whatevers" |
|
end |
|
|
|
def get_all(session, parent_path) |
|
a = ["one", "two", "three"] |
|
class <<a |
|
attr_accessor :called |
|
|
|
def size |
|
@called = true |
|
9 |
|
end |
|
end |
|
|
|
a |
|
end |
|
|
|
def get(session, id, parent_path) |
|
"hello" |
|
end |
|
end |
|
end |
|
|
|
class ResourceCollectionTest < Test::Unit::TestCase |
|
def setup |
|
@collection ||= Wufoo::ResourceCollection.new(StubResource, "fake session") |
|
end |
|
|
|
def test_delegation |
|
assert_equal 9, @collection.size |
|
assert @collection.to_a.called |
|
end |
|
|
|
def test_reload |
|
assert_equal ["one", "two", "three"], @collection.reload |
|
assert_equal ["one", "two", "three"], @collection.to_a |
|
end |
|
|
|
def test_find |
|
assert_equal "hello", @collection.find(1234) |
|
end |
|
end |
|
|
|
class PostableCollectionTest < Test::Unit::TestCase |
|
def setup |
|
@collection ||= Wufoo::PostableCollection.new(StubResource, Wufoo.login("hi", "hello")) |
|
|
|
class <<@collection |
|
def post_resource(url, attrs) |
|
{"Success" => "1", "EntryID" => "1"} |
|
end |
|
end |
|
end |
|
|
|
def test_create |
|
assert @collection.create("Field1" => "Hello!") |
|
end |
|
|
|
def test_create! |
|
assert_nothing_raised do |
|
@collection.create!("Field1" => "Hello!") |
|
end |
|
end |
|
end |
|
|
|
class ResourceTest < Test::Unit::TestCase |
|
class Fake < Wufoo::Resource |
|
end |
|
|
|
class Party < Wufoo::Resource |
|
resource_collection_name "parties" |
|
end |
|
|
|
def setup |
|
@session ||= Wufoo.login("hello", "goodbye") |
|
end |
|
|
|
def test_base_name |
|
assert "Fake", Fake.base_name |
|
end |
|
|
|
def test_collection_path |
|
assert_equal "fakes.json", Fake.collection_path |
|
end |
|
|
|
def test_collection_path_with_parent |
|
assert_equal "realies/19/fakes.json", Fake.collection_path("realies/19/%s") |
|
end |
|
|
|
def test_resource_path |
|
assert_equal "fakes/19.json", Fake.resource_path(19) |
|
end |
|
|
|
def test_resource_path_with_parent |
|
assert_equal "realies/288/fakes/23.json", Fake.resource_path(23, "realies/288/%s") |
|
end |
|
|
|
def test_collection_name_manual_set |
|
assert_equal "parties.json", Party.collection_path |
|
end |
|
|
|
def test_from_params |
|
obj = Fake.from_params({'thing' => "first", 'what' => "second"}, @session) |
|
assert_equal ({'thing' => "first", 'what' => "second"}), obj.attrs |
|
end |
|
|
|
def test_attr_methods |
|
obj = Fake.from_params({'thing' => "first", 'what' => "second"}, @session) |
|
assert_equal "first", obj.thing |
|
end |
|
end |
|
|
|
class UserTest < Test::Unit::TestCase |
|
def setup |
|
@u ||= Wufoo::User.from_params({'Image' => 'hiya.jpg'}, Wufoo.login("dude", "dudette")) |
|
end |
|
|
|
def test_avatar_url |
|
assert_equal "https://dude.wufoo.com/api/v3/images/avatars/big/hiya.jpg", @u.avatar_url |
|
end |
|
|
|
def test_avatar_url |
|
assert_equal "https://dude.wufoo.com/api/v3/images/avatars/big/hiya.jpg", @u.avatar_url |
|
end |
|
end |
|
|
|
class FormTest < Test::Unit::TestCase |
|
def setup |
|
@form = Wufoo::Form.from_params({'Name' => "Untitled", 'Hash' => "1234"}, Wufoo.login("pirate", "princess")) |
|
end |
|
|
|
def test_parental_path |
|
assert_equal "forms/1234/%s", @form.parental_path |
|
end |
|
|
|
def test_fields |
|
assert @form.fields.is_a?(Wufoo::ResourceCollection) |
|
assert_equal Wufoo::Field, @form.fields.resource_class |
|
assert_equal "forms/1234/%s", @form.fields.parent_path |
|
end |
|
|
|
def test_entries |
|
assert @form.entries.is_a?(Wufoo::ResourceCollection) |
|
assert_equal Wufoo::Entry, @form.entries.resource_class |
|
assert_equal "forms/1234/%s", @form.entries.parent_path |
|
end |
|
|
|
def test_comments |
|
assert @form.comments.is_a?(Wufoo::ResourceCollection) |
|
assert_equal Wufoo::Comment, @form.comments.resource_class |
|
assert_equal "forms/1234/%s", @form.comments.parent_path |
|
end |
|
end |
|
|
|
class ReportTest < Test::Unit::TestCase |
|
def setup |
|
@report = Wufoo::Report.from_params({'Name' => "Untitled", 'Hash' => "1234"}, Wufoo.login("pirate", "princess")) |
|
end |
|
|
|
def test_parental_path |
|
assert_equal "reports/1234/%s", @report.parental_path |
|
end |
|
|
|
def test_fields |
|
assert @report.fields.is_a?(Wufoo::ResourceCollection) |
|
assert_equal Wufoo::Field, @report.fields.resource_class |
|
assert_equal "reports/1234/%s", @report.fields.parent_path |
|
end |
|
|
|
def test_entries |
|
assert @report.entries.is_a?(Wufoo::ResourceCollection) |
|
assert_equal Wufoo::Entry, @report.entries.resource_class |
|
assert_equal "reports/1234/%s", @report.entries.parent_path |
|
end |
|
|
|
def test_widgets |
|
assert @report.widgets.is_a?(Wufoo::ResourceCollection) |
|
assert_equal Wufoo::Widget, @report.widgets.resource_class |
|
assert_equal "reports/1234/%s", @report.widgets.parent_path |
|
end |
|
end |