Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

minor: whitespace

  • Loading branch information...
commit 73e896da6e059b4d88330130d758846ab8771ec9 1 parent 357a4ab
@djsun authored
Showing with 694 additions and 689 deletions.
  1. +1 −1  README.mdown
  2. +1 −1  examples/datacatalog/Rakefile
  3. +5 −5 examples/datacatalog/config/config.rb
  4. +2 −2 examples/datacatalog/lib/base.rb
  5. +5 −5 examples/datacatalog/lib/resource.rb
  6. +2 −2 examples/datacatalog/lib/roles.rb
  7. +6 −6 examples/datacatalog/model_helpers/search.rb
  8. +1 −1  examples/datacatalog/models/categorization.rb
  9. +1 −1  examples/datacatalog/models/note.rb
  10. +3 −3 examples/datacatalog/models/source.rb
  11. +2 −2 examples/datacatalog/models/usage.rb
  12. +7 −7 examples/datacatalog/models/user.rb
  13. +7 −7 examples/datacatalog/resources/categories.rb
  14. +4 −4 examples/datacatalog/resources/categories_sources.rb
  15. +1 −1  examples/datacatalog/resources/notes.rb
  16. +3 −3 examples/datacatalog/resources/sources.rb
  17. +3 −3 examples/datacatalog/resources/sources_usages.rb
  18. +3 −3 examples/datacatalog/resources/users.rb
  19. +2 −2 examples/datacatalog/tasks/db.rake
  20. +1 −1  examples/datacatalog/tasks/test.rake
  21. +1 −1  examples/datacatalog/test/helpers/assertions/assert_include.rb
  22. +1 −1  examples/datacatalog/test/helpers/assertions/assert_not_include.rb
  23. +7 −7 examples/datacatalog/test/helpers/lib/model_factories.rb
  24. +1 −1  examples/datacatalog/test/helpers/lib/model_helpers.rb
  25. +7 −7 examples/datacatalog/test/helpers/lib/request_helpers.rb
  26. +8 −8 examples/datacatalog/test/helpers/shared/api_keys.rb
  27. +1 −1  examples/datacatalog/test/helpers/shared/common_body_responses.rb
  28. +2 −2 examples/datacatalog/test/helpers/shared/model_counts.rb
  29. +4 −4 examples/datacatalog/test/helpers/shared/status_codes.rb
  30. +4 −4 examples/datacatalog/test/helpers/test_cases/resource_test_case.rb
  31. +6 −6 examples/datacatalog/test/models/categorization_test.rb
  32. +8 −8 examples/datacatalog/test/models/category_test.rb
  33. +6 −6 examples/datacatalog/test/models/note_test.rb
  34. +4 −4 examples/datacatalog/test/models/search_test.rb
  35. +5 −5 examples/datacatalog/test/models/source_test.rb
  36. +11 −11 examples/datacatalog/test/models/user_test.rb
  37. +11 −11 examples/datacatalog/test/resources/categories/categories_delete_test.rb
  38. +9 −9 examples/datacatalog/test/resources/categories/categories_get_many_test.rb
  39. +7 −7 examples/datacatalog/test/resources/categories/categories_get_one_test.rb
  40. +16 −16 examples/datacatalog/test/resources/categories/categories_post_test.rb
  41. +17 −17 examples/datacatalog/test/resources/categories/categories_put_test.rb
  42. +25 −25 examples/datacatalog/test/resources/categories_sources/categories_sources_delete_test.rb
  43. +5 −5 examples/datacatalog/test/resources/categories_sources/categories_sources_get_many_test.rb
  44. +15 −15 examples/datacatalog/test/resources/categories_sources/categories_sources_get_one_test.rb
  45. +31 −31 examples/datacatalog/test/resources/categories_sources/categories_sources_post_test.rb
  46. +41 −41 examples/datacatalog/test/resources/categories_sources/categories_sources_put_test.rb
  47. +15 −15 examples/datacatalog/test/resources/notes/notes_get_many_test.rb
  48. +7 −7 examples/datacatalog/test/resources/notes/notes_get_one_test.rb
  49. +12 −12 examples/datacatalog/test/resources/notes/notes_post_test.rb
  50. +11 −11 examples/datacatalog/test/resources/sources/sources_delete_test.rb
  51. +20 −20 examples/datacatalog/test/resources/sources/sources_get_many_search_test.rb
  52. +8 −8 examples/datacatalog/test/resources/sources/sources_get_many_test.rb
  53. +15 −9 examples/datacatalog/test/resources/sources/sources_get_one_test.rb
  54. +13 −13 examples/datacatalog/test/resources/sources/sources_post_test.rb
  55. +30 −30 examples/datacatalog/test/resources/sources/sources_put_test.rb
  56. +24 −24 examples/datacatalog/test/resources/sources_usages/sources_usages_delete_test.rb
  57. +9 −9 examples/datacatalog/test/resources/sources_usages/sources_usages_get_many_filter_test.rb
  58. +9 −9 examples/datacatalog/test/resources/sources_usages/sources_usages_get_many_test.rb
  59. +15 −15 examples/datacatalog/test/resources/sources_usages/sources_usages_get_one_test.rb
  60. +16 −16 examples/datacatalog/test/resources/sources_usages/sources_usages_post_test.rb
  61. +33 −33 examples/datacatalog/test/resources/sources_usages/sources_usages_put_test.rb
  62. +19 −19 examples/datacatalog/test/resources/users/users_delete_test.rb
  63. +16 −16 examples/datacatalog/test/resources/users/users_get_many_test.rb
  64. +8 −8 examples/datacatalog/test/resources/users/users_get_one_test.rb
  65. +13 −13 examples/datacatalog/test/resources/users/users_post_test.rb
  66. +18 −18 examples/datacatalog/test/resources/users/users_put_test.rb
  67. +10 −10 lib/builder.rb
  68. +8 −8 lib/builder/action_definitions.rb
  69. +7 −7 lib/builder/helpers.rb
  70. +13 −14 lib/builder/mongo_helpers.rb
  71. +1 −1  lib/exceptions.rb
  72. +20 −20 lib/resource.rb
  73. +2 −2 lib/roles.rb
  74. +6 −6 notes/permissions.mdown
  75. +1 −1  spec/spec_helper.rb
  76. +2 −2 spec/utility_spec.rb
View
2  README.mdown
@@ -16,7 +16,7 @@ You will need gemcutter if you don't have it already:
I recommend a user-level install:
gem install resource_sinatra
-
+
Note: in general, beware of `sudo gem install <project_name>` -- it gives elevated privileges. Do you trust `<project name>`? Better to be safe and use a local install to `~/.gem`.
## Usage
View
2  examples/datacatalog/Rakefile
@@ -13,7 +13,7 @@ namespace :environment do
puts "Loading application environment..."
require File.dirname(__FILE__) + '/app'
end
-
+
task :models do
puts "Loading models..."
Config.setup_mongomapper
View
10 examples/datacatalog/config/config.rb
@@ -4,17 +4,17 @@
require 'mongo_mapper'
module Config
-
+
def self.setup
setup_mongomapper
# More application setup can go here...
end
-
+
def self.setup_mongomapper
MongoMapper.connection = new_mongo_connection
MongoMapper.database = environment_config['mongo_database']
end
-
+
def self.new_mongo_connection
Mongo::Connection.new(environment_config["mongo_hostname"])
end
@@ -44,7 +44,7 @@ def self.environment
end
end
end
-
+
def self.environment=(env)
@environment = env
end
@@ -52,7 +52,7 @@ def self.environment=(env)
def self.environments
config.keys
end
-
+
def self.config
if @config
@config
View
4 examples/datacatalog/lib/base.rb
@@ -1,9 +1,9 @@
module DataCatalog
-
+
class Base < Sinatra::Base
before do
content_type :json
end
end
-
+
end
View
10 examples/datacatalog/lib/resource.rb
@@ -1,9 +1,9 @@
require 'uri'
module DataCatalog
-
+
module Resource
-
+
def self.included(includee)
includee.instance_eval do
include SinatraResource::Resource
@@ -21,12 +21,12 @@ def before_authorization(action, role, resource_config)
def convert(object)
object == "" ? "" : object.to_json
end
-
+
def full_uri(path)
base_uri = Config.environment_config["base_uri"]
URI.join(base_uri, path).to_s
end
-
+
def log_event(event, params)
# Application-logic could go here.
end
@@ -73,5 +73,5 @@ def user_for(api_key)
end
end
-
+
end
View
4 examples/datacatalog/lib/roles.rb
@@ -1,10 +1,10 @@
require File.expand_path(File.dirname(__FILE__) + '/../../../lib/sinatra_resource')
module DataCatalog
-
+
module Roles
include SinatraResource::Roles
-
+
role :anonymous
role :basic => :anonymous
role :owner => :basic
View
12 examples/datacatalog/model_helpers/search.rb
@@ -1,7 +1,7 @@
module DataCatalog
-
+
class Search
-
+
# Returns an array of strings, tokenized with stopwords removed.
#
# @param [<String>] array
@@ -11,7 +11,7 @@ class Search
def self.process(array)
unstop(tokenize(array))
end
-
+
# Tokenize an array of strings.
#
# @param [<String>] array
@@ -25,7 +25,7 @@ def self.tokenize(array)
end
REMOVE = %r([!,;])
-
+
# Tokenize a string, removing extra characters too.
#
# @param [String] string
@@ -86,7 +86,7 @@ def self.tokens(s)
def self.unstop(array)
array - STOP_WORDS
end
-
+
end
-
+
end
View
2  examples/datacatalog/models/categorization.rb
@@ -18,7 +18,7 @@ class Categorization
belongs_to :category, :class_name => 'DataCatalog::Category'
# == Validations
-
+
validate :validate_associations
def validate_associations
View
2  examples/datacatalog/models/note.rb
@@ -9,7 +9,7 @@ class Note
key :text, String
key :user_id, ObjectId
timestamps!
-
+
# == Indices
# == Associations
View
6 examples/datacatalog/models/source.rb
@@ -1,5 +1,5 @@
module DataCatalog
-
+
class Source
include MongoMapper::Document
@@ -35,9 +35,9 @@ def categories
validates_presence_of :title
validates_presence_of :url
-
+
# == Callbacks
-
+
before_save :update_keywords
def update_keywords
self._keywords = DataCatalog::Search.process([title, description])
View
4 examples/datacatalog/models/usage.rb
@@ -1,7 +1,7 @@
module DataCatalog
class Usage
-
+
include MongoMapper::EmbeddedDocument
# == Attributes
@@ -21,7 +21,7 @@ class Usage
#
# validates_presence_of :title
# validates_presence_of :url
-
+
# == Class Methods
# == Various Instance Methods
View
14 examples/datacatalog/models/user.rb
@@ -1,9 +1,9 @@
require 'digest/sha1'
module DataCatalog
-
+
class User
-
+
include MongoMapper::Document
# == Attributes
@@ -19,7 +19,7 @@ class User
ensure_index :email
# == Validations
-
+
validates_presence_of :name
validates_presence_of :role
validate :validate_role
@@ -31,9 +31,9 @@ def validate_role
errors.add(:role, "must be in #{VALID_ROLES.inspect}")
end
end
-
+
# == Callbacks
-
+
before_create :assign_api_key
def assign_api_key
unless _api_key
@@ -46,9 +46,9 @@ def generate_api_key
s = "#{Time.now.to_f}#{salt}#{rand(100_000_000)}#{name}#{email}"
Digest::SHA1.hexdigest(s)
end
-
+
# == Various Instance Methods
-
+
def token
Digest::SHA1.hexdigest("#{id}/#{email}/123456789")
end
View
14 examples/datacatalog/resources/categories.rb
@@ -15,7 +15,7 @@ class Categories < Base
permission :delete => :curator
# == Properties
-
+
property :name
property :log
@@ -29,13 +29,13 @@ class Categories < Base
}
end
end
-
+
# == Callbacks
-
+
callback :before_create do |action|
action.params["log"] = "before_create"
end
-
+
callback :after_create do |action, category|
category.log += " after_create"
end
@@ -43,7 +43,7 @@ class Categories < Base
callback :before_update do |action, category|
action.params["log"] = "before_update"
end
-
+
callback :after_update do |action, category|
category.log += " after_update"
end
@@ -51,14 +51,14 @@ class Categories < Base
callback :before_destroy do |action, category|
action.headers 'X-Test-Callbacks' => 'before_destroy'
end
-
+
callback :after_destroy do |action, category|
x = action.response['X-Test-Callbacks']
action.headers 'X-Test-Callbacks' => "#{x} after_destroy"
end
end
-
+
Categories.build
end
View
8 examples/datacatalog/resources/categories_sources.rb
@@ -14,7 +14,7 @@ class CategoriesSources < Base
:source_id => child.id
)
end
-
+
relation :delete do |parent, child|
Categorization.find(:conditions => {
:category_id => parent.id,
@@ -30,7 +30,7 @@ class CategoriesSources < Base
permission :create => :curator
permission :update => :curator
permission :delete => :curator
-
+
# == Properties
property :title
@@ -38,9 +38,9 @@ class CategoriesSources < Base
property :raw, :w => :admin
# == Callbacks
-
+
end
-
+
CategoriesSources.build
end
View
2  examples/datacatalog/resources/notes.rb
@@ -22,7 +22,7 @@ class Notes < Base
# == Callbacks
end
-
+
Notes.build
end
View
6 examples/datacatalog/resources/sources.rb
@@ -13,13 +13,13 @@ class Sources < Base
permission :create => :curator
permission :update => :curator
permission :delete => :curator
-
+
# == Properties
property :title
property :url
property :raw, :w => :admin, :hide_by_default => true
-
+
property :categories do |source|
source.categorizations.map do |categorization|
{
@@ -32,7 +32,7 @@ class Sources < Base
# == Callbacks
end
-
+
Sources.build
end
View
6 examples/datacatalog/resources/sources_usages.rb
@@ -16,7 +16,7 @@ class SourcesUsages < Base
permission :create => :curator
permission :update => :curator
permission :delete => :curator
-
+
# == Properties
property :title
@@ -24,9 +24,9 @@ class SourcesUsages < Base
property :description
# == Callbacks
-
+
end
-
+
SourcesUsages.build
end
View
6 examples/datacatalog/resources/users.rb
@@ -15,19 +15,19 @@ class Users < Base
permission :delete => :owner
# == Properties
-
+
property :name, :r => :basic
property :email, :r => :owner
property :role, :r => :owner, :w => :admin
property :_api_key, :r => :owner, :w => :admin
-
+
property :token, :r => :owner do |user|
user.token
end
# == Callbacks
end
-
+
Users.build
end
View
4 examples/datacatalog/tasks/db.rake
@@ -1,5 +1,5 @@
namespace :db do
-
+
def verbosely_drop_database
db_name = Config.drop_database
puts "Dropped database: #{db_name}."
@@ -25,5 +25,5 @@ namespace :db do
verbosely_drop_database
end
end
-
+
end
View
2  examples/datacatalog/tasks/test.rake
@@ -2,7 +2,7 @@ desc "Run tests"
task :test => %w(db:reset:test test:models test:resources)
namespace :test do
-
+
desc "Run model tests"
Rake::TestTask.new(:models) do |t|
t.test_files = FileList["test/models/*_test.rb"]
View
2  examples/datacatalog/test/helpers/assertions/assert_include.rb
@@ -11,7 +11,7 @@ def assert_include(expected, actual, message = nil)
end
end
end
-
+
end
end
end
View
2  examples/datacatalog/test/helpers/assertions/assert_not_include.rb
@@ -11,7 +11,7 @@ def assert_not_include(expected, actual, message = nil)
end
end
end
-
+
end
end
end
View
14 examples/datacatalog/test/helpers/lib/model_factories.rb
@@ -1,25 +1,25 @@
module ModelFactories
-
+
def create_source(custom={})
create_model!(DataCatalog::Source, custom, {
:title => "Healthcare Spending Data",
:url => "http://data.gov/details/23",
})
end
-
+
def create_category(custom={})
create_model!(DataCatalog::Category, custom, {
:name => "Sample Category",
})
end
-
+
def create_categorization(custom={})
create_model!(DataCatalog::Categorization, custom, {
:source_id => "",
:category_id => "",
})
end
-
+
def create_note(custom={})
create_model!(DataCatalog::Note, custom, {
:text => "Sample Note",
@@ -34,9 +34,9 @@ def create_user(custom={})
:role => "basic",
})
end
-
+
# -----
-
+
def new_usage(custom={})
new_model!(DataCatalog::Usage, custom, {
:title => "Sample Usage",
@@ -62,5 +62,5 @@ def new_model!(klass, custom, required)
end
model
end
-
+
end
View
2  examples/datacatalog/test/helpers/lib/model_helpers.rb
@@ -3,7 +3,7 @@ module ModelHelpers
def self.included(includee)
includee.extend(ClassMethods)
end
-
+
module ClassMethods
# Is a document (looked up from +symbol+) missing +key+?
View
14 examples/datacatalog/test/helpers/lib/request_helpers.rb
@@ -8,7 +8,7 @@ def parsed_response_body
Crack::JSON.parse(s)
end
end
-
+
def assert_properties(correct, parsed_document)
correct.each do |property|
assert_include property, parsed_document
@@ -19,7 +19,7 @@ def assert_properties(correct, parsed_document)
def self.included(includee)
includee.extend(ClassMethods)
end
-
+
module ClassMethods
def doc_properties(correct)
test "document should only have correct attributes" do
@@ -34,13 +34,13 @@ def docs_properties(correct)
end
end
end
-
+
def invalid_param(s)
test "should report #{s} as invalid" do
assert_include s.to_s, parsed_response_body["errors"]["invalid_params"]
end
end
-
+
def missing_param(s)
test "should report missing #{s}" do
assert_include "can't be empty", parsed_response_body["errors"][s.to_s]
@@ -55,7 +55,7 @@ def location_header(path)
assert_equal expected, last_response.headers['Location']
end
end
-
+
def nested_location_header(parent_path, parent_ivar, child_path)
test "should set Location header correctly" do
base_uri = Config.environment_config["base_uri"]
@@ -67,8 +67,8 @@ def nested_location_header(parent_path, parent_ivar, child_path)
assert_equal expected, last_response.headers['Location']
end
end
-
+
end
-
+
end
View
16 examples/datacatalog/test/helpers/shared/api_keys.rb
@@ -2,7 +2,7 @@ class ResourceTestCase
shared "return 400 because no params were given" do
use "return 400 Bad Request"
-
+
test "body should say no params were given" do
assert_include "errors", parsed_response_body
assert_include "no_params", parsed_response_body["errors"]
@@ -11,34 +11,34 @@ class ResourceTestCase
shared "return 400 because params were not empty" do
use "return 400 Bad Request"
-
+
test "body should say params were non-empty" do
assert_include "errors", parsed_response_body
assert_include "non_empty_params", parsed_response_body["errors"]
end
end
-
+
shared "return 401 because the API key is invalid" do
use "return 401 Unauthorized"
-
+
test "body should say the API key is invalid" do
assert_include "errors", parsed_response_body
assert_include "invalid_api_key", parsed_response_body["errors"]
end
end
-
+
shared "return 401 because the API key is missing" do
use "return 401 Unauthorized"
-
+
test "body should say the API key is missing" do
assert_include "errors", parsed_response_body
assert_include "missing_api_key", parsed_response_body["errors"]
end
end
-
+
shared "return 401 because the API key is unauthorized" do
use "return 401 Unauthorized"
-
+
test "body should say the API key is unauthorized" do
assert_include "errors", parsed_response_body
assert_include "unauthorized_api_key", parsed_response_body["errors"]
View
2  examples/datacatalog/test/helpers/shared/common_body_responses.rb
@@ -11,7 +11,7 @@ class ResourceTestCase
assert_equal [], parsed_response_body
end
end
-
+
shared "content type header indicates JSON" do
test "should have JSON content type" do
assert_equal "application/json", last_response.headers["Content-Type"]
View
4 examples/datacatalog/test/helpers/shared/model_counts.rb
@@ -1,5 +1,5 @@
class ResourceTestCase
-
+
# == categories
shared "no change in category count" do
@@ -13,7 +13,7 @@ class ResourceTestCase
assert_equal @category_count - 1, DataCatalog::Category.all.length
end
end
-
+
shared "one new category" do
test "should add one category document to database" do
assert_equal @category_count + 1, DataCatalog::Category.all.length
View
8 examples/datacatalog/test/helpers/shared/status_codes.rb
@@ -1,5 +1,5 @@
class ResourceTestCase
-
+
shared "return 200 Ok" do
test "status should be 200 Ok" do
assert_equal 200, last_response.status
@@ -12,7 +12,7 @@ class ResourceTestCase
test "status should be 201 Created" do
assert_equal 201, last_response.status
end
-
+
test "location header should start with http://localhost" do
assert_include "Location", last_response.headers
generic_uri = %r{^http://localhost}
@@ -26,7 +26,7 @@ class ResourceTestCase
test "status should be 204 No Content" do
assert_equal 204, last_response.status
end
-
+
use "return an empty response body"
use "content type header not set"
end
@@ -65,7 +65,7 @@ class ResourceTestCase
shared "return 404 Not Found with empty response body" do
use "return 404 Not Found"
-
+
use "return an empty response body"
end
View
8 examples/datacatalog/test/helpers/test_cases/resource_test_case.rb
@@ -14,15 +14,15 @@ class ResourceTestCase < Test::Unit::TestCase
)
end
end
-
+
after :all do
@users_by_role.each_pair { |role, user| user.destroy }
end
-
+
def user_for(role)
@users_by_role[role]
end
-
+
def api_key_for(role)
key = @users_by_role[role]._api_key
raise "API key not found" unless key
@@ -32,5 +32,5 @@ def api_key_for(role)
def valid_params_for(role)
@valid_params.merge(:api_key => api_key_for(role))
end
-
+
end
View
12 examples/datacatalog/test/models/categorization_test.rb
@@ -1,9 +1,9 @@
require File.expand_path(File.dirname(__FILE__) + '/../helpers/model_test_helper')
class CategorizationTest < ModelTestCase
-
+
include DataCatalog
-
+
context "Categorization" do
before do
@source = create_source
@@ -13,13 +13,13 @@ class CategorizationTest < ModelTestCase
:category_id => @category.id
)
end
-
+
after do
@source.destroy
@category.destroy
@categorization.destroy
end
-
+
test "Categorization#source is correct" do
assert_equal @source, @categorization.source
end
@@ -27,11 +27,11 @@ class CategorizationTest < ModelTestCase
test "Categorization#category is correct" do
assert_equal @category, @categorization.category
end
-
+
test "Source#categorization is correct" do
assert_equal [@categorization], @source.categorizations
end
-
+
test "Category#categorization is correct" do
assert_equal [@categorization], @category.categorizations
end
View
16 examples/datacatalog/test/models/category_test.rb
@@ -1,7 +1,7 @@
require File.expand_path(File.dirname(__FILE__) + '/../helpers/model_test_helper')
class CategoryTest < ModelTestCase
-
+
include DataCatalog
before do
@@ -15,33 +15,33 @@ class CategoryTest < ModelTestCase
before do
@category = Category.new(@required)
end
-
+
test "should be valid" do
assert_equal true, @category.valid?
end
end
-
+
[:name].each do |missing|
context "missing #{missing}" do
before do
@category = Category.new(@required.delete_if { |k, v| k == missing })
end
-
+
missing_key(:category, missing)
end
end
end
-
+
context "Category with 0 categorizations" do
before do
@category = Category.create(@required)
end
-
+
test "#sources should be empty" do
assert_equal [], @category.sources
end
end
-
+
context "Category with 3 categorizations" do
before do
@category = Category.create(@required)
@@ -57,7 +57,7 @@ class CategoryTest < ModelTestCase
)
end
end
-
+
test "#sources should have 3 categorizations" do
categorizations = @category.categorizations
assert_equal 3, categorizations.length
View
12 examples/datacatalog/test/models/note_test.rb
@@ -1,7 +1,7 @@
require File.expand_path(File.dirname(__FILE__) + '/../helpers/model_test_helper')
class NoteTest < ModelTestCase
-
+
include DataCatalog
context "Note" do
@@ -12,16 +12,16 @@ class NoteTest < ModelTestCase
:user_id => @user.id
}
end
-
+
after do
@user.destroy
end
-
+
context "correct params" do
before do
@note = Note.new(@required)
end
-
+
test "should be valid" do
assert_equal true, @note.valid?
end
@@ -32,11 +32,11 @@ class NoteTest < ModelTestCase
before do
@note = Note.new(@required.delete_if { |k, v| k == missing })
end
-
+
missing_key(:note, missing)
end
end
end
-
+
end
View
8 examples/datacatalog/test/models/search_test.rb
@@ -25,20 +25,20 @@ class SearchUnitTest < ModelTestCase
Search.tokens("The earth has an axial tilt of 23.439 degrees.")
end
end
-
+
context "tokenize" do
test "simple" do
assert_equal %w(aerospace defense systems),
Search.tokenize(["aerospace defense", "defense systems"])
end
end
-
+
context "unstop" do
test "simple" do
assert_equal %w(big brown fox), Search.unstop(%w(the big brown fox))
end
end
-
+
context "process" do
test "simple" do
assert_equal %w(aerospace defense systems),
@@ -50,5 +50,5 @@ class SearchUnitTest < ModelTestCase
Search.process(["The earth has an axial tilt of 23.439 degrees."])
end
end
-
+
end
View
10 examples/datacatalog/test/models/source_test.rb
@@ -1,7 +1,7 @@
require File.expand_path(File.dirname(__FILE__) + '/../helpers/model_test_helper')
class SourceTest < ModelTestCase
-
+
include DataCatalog
context "Source" do
@@ -11,12 +11,12 @@ class SourceTest < ModelTestCase
:url => "http://moneybags.gov/data/2009"
}
end
-
+
context "correct params" do
before do
@source = Source.new(@required)
end
-
+
test "should be valid" do
assert_equal true, @source.valid?
end
@@ -27,11 +27,11 @@ class SourceTest < ModelTestCase
before do
@source = Source.new(@required.delete_if { |k, v| k == missing })
end
-
+
missing_key(:source, missing)
end
end
end
-
+
end
View
22 examples/datacatalog/test/models/user_test.rb
@@ -1,7 +1,7 @@
require File.expand_path(File.dirname(__FILE__) + '/../helpers/model_test_helper')
class UserTest < ModelTestCase
-
+
include DataCatalog
context "User#new" do
@@ -11,27 +11,27 @@ class UserTest < ModelTestCase
:role => "basic"
}
end
-
+
context "correct params" do
before do
@user = User.new(@required)
end
-
+
test "should be valid" do
assert_equal true, @user.valid?
end
-
+
test "should not set api_key" do
assert_equal nil, @user._api_key
end
end
-
+
[:name, :role].each do |missing|
context "missing #{missing}" do
before do
@user = User.new(@required.delete_if { |k, v| k == missing })
end
-
+
missing_key(:user, missing)
end
end
@@ -41,7 +41,7 @@ class UserTest < ModelTestCase
@user = User.new(@required.merge(:role => "owner"))
# owner is not a 'fixed' role, it is a 'relative' role
end
-
+
test "should be invalid" do
assert_equal false, @user.valid?
end
@@ -58,20 +58,20 @@ class UserTest < ModelTestCase
before do
@user = User.create(@required)
end
-
+
after do
@user.destroy
end
-
+
test "should be valid" do
assert_equal true, @user.valid?
end
-
+
test "should set api_key" do
assert_not_equal nil, @user._api_key
end
end
end
end
-
+
end
View
22 examples/datacatalog/test/resources/categories/categories_delete_test.rb
@@ -20,7 +20,7 @@ def app; Categories end
before do
delete "/#{@category.id}"
end
-
+
use "return 401 because the API key is missing"
use "no change in category count"
end
@@ -29,18 +29,18 @@ def app; Categories end
before do
delete "/#{@category.id}", :api_key => BAD_API_KEY
end
-
+
use "return 401 because the API key is invalid"
use "no change in category count"
end
end
-
+
%w(basic).each do |role|
context "#{role} : delete /:fake_id" do
before do
delete "/#{FAKE_ID}", :api_key => api_key_for(role)
end
-
+
use "return 401 because the API key is unauthorized"
use "no change in category count"
end
@@ -51,7 +51,7 @@ def app; Categories end
:api_key => api_key_for(role),
:key => "value"
end
-
+
use "return 401 because the API key is unauthorized"
use "no change in category count"
end
@@ -60,7 +60,7 @@ def app; Categories end
before do
delete "/#{@category.id}", :api_key => api_key_for(role)
end
-
+
use "return 401 because the API key is unauthorized"
use "no change in category count"
end
@@ -71,7 +71,7 @@ def app; Categories end
before do
delete "/#{FAKE_ID}", :api_key => api_key_for(role)
end
-
+
use "return 404 Not Found with empty response body"
use "no change in category count"
end
@@ -82,7 +82,7 @@ def app; Categories end
:api_key => api_key_for(role),
:key => "value"
end
-
+
use "return 400 because params were not empty"
use "no change in category count"
end
@@ -91,15 +91,15 @@ def app; Categories end
before do
delete "/#{@category.id}", :api_key => api_key_for(role)
end
-
+
use "return 204 No Content"
use "one less category"
-
+
test "callbacks should work" do
actual = last_response.headers['X-Test-Callbacks']
assert_equal "before_destroy after_destroy", actual
end
end
end
-
+
end
View
18 examples/datacatalog/test/resources/categories/categories_get_many_test.rb
@@ -14,11 +14,11 @@ def app; Categories end
create_category(:name => "Category #{i}")
end
end
-
+
after do
@categories.each { |x| x.destroy } if @categories
end
-
+
CATEGORIES = ["Category 0", "Category 1", "Category 2"].sort
context "get /" do
@@ -26,15 +26,15 @@ def app; Categories end
before do
get "/"
end
-
+
use "return 401 because the API key is missing"
end
-
+
context "incorrect API key" do
before do
get "/", :api_key => BAD_API_KEY
end
-
+
use "return 401 because the API key is invalid"
end
end
@@ -45,18 +45,18 @@ def app; Categories end
get "/", :api_key => api_key_for(role)
@members = parsed_response_body['members']
end
-
+
use "return 200 Ok"
-
+
test "body should have 3 categories" do
assert_equal 3, @members.length
end
-
+
test "body should have correct category names" do
actual = @members.map { |e| e["name"] }
assert_equal CATEGORIES, actual.sort
end
-
+
test "members should only have correct attributes" do
correct = %w(name log sources id created_at updated_at)
@members.each do |member|
View
14 examples/datacatalog/test/resources/categories/categories_get_one_test.rb
@@ -5,11 +5,11 @@ class CategoriesGetOneResourceTest < ResourceTestCase
include DataCatalog
def app; Categories end
-
+
before do
@category = create_category
end
-
+
after do
@category.destroy
end
@@ -19,7 +19,7 @@ def app; Categories end
before do
get "/#{@category.id}"
end
-
+
use "return 401 because the API key is missing"
end
@@ -27,7 +27,7 @@ def app; Categories end
before do
get "/#{@category.id}", :api_key => BAD_API_KEY
end
-
+
use "return 401 because the API key is invalid"
end
end
@@ -37,7 +37,7 @@ def app; Categories end
before do
get "/#{FAKE_ID}", :api_key => api_key_for(role)
end
-
+
use "return 404 Not Found with empty response body"
end
@@ -50,7 +50,7 @@ def app; Categories end
)
get "/#{@category.id}", :api_key => api_key_for(role)
end
-
+
after do
@source.destroy
@categorization.destroy
@@ -58,7 +58,7 @@ def app; Categories end
use "return 200 Ok"
doc_properties %w(name log id created_at updated_at sources)
-
+
test "body should have correct sources" do
expected = [
{
View
32 examples/datacatalog/test/resources/categories/categories_post_test.rb
@@ -18,7 +18,7 @@ def app; Categories end
before do
post "/", @valid_params
end
-
+
use "return 401 because the API key is missing"
use "no change in category count"
end
@@ -27,40 +27,40 @@ def app; Categories end
before do
post "/", @valid_params.merge(:api_key => BAD_API_KEY)
end
-
+
use "return 401 because the API key is invalid"
use "no change in category count"
end
end
-
+
%w(basic).each do |role|
[:name].each do |missing|
context "#{role} : post / but missing #{missing}" do
before do
post "/", valid_params_for(role).delete_if { |k, v| k == missing }
end
-
+
use "return 401 because the API key is unauthorized"
use "no change in category count"
end
end
-
+
[:id, :created_at, :updated_at, :sources, :junk].each do |invalid|
context "#{role} : post / but with #{invalid}" do
before do
post "/", valid_params_for(role).merge(invalid => 9)
end
-
+
use "return 401 because the API key is unauthorized"
use "no change in category count"
end
end
-
+
context "#{role} : post / with valid params" do
before do
post "/", valid_params_for(role)
end
-
+
use "return 401 because the API key is unauthorized"
use "no change in category count"
end
@@ -72,39 +72,39 @@ def app; Categories end
before do
post "/", valid_params_for(role).delete_if { |k, v| k == missing }
end
-
+
use "return 400 Bad Request"
use "no change in category count"
missing_param missing
end
end
-
+
[:id, :created_at, :updated_at, :sources, :junk].each do |invalid|
context "#{role} : post / but with #{invalid}" do
before do
post "/", valid_params_for(role).merge(invalid => 9)
end
-
+
use "return 400 Bad Request"
use "no change in category count"
invalid_param invalid
end
end
-
+
context "#{role} : post / with valid params" do
before do
post "/", valid_params_for(role)
end
-
+
after do
Category.find_by_id(parsed_response_body["id"]).destroy
end
-
+
use "return 201 Created"
location_header "categories"
use "one new category"
doc_properties %w(name log id created_at updated_at sources)
-
+
test "should set all fields in database" do
category = Category.find_by_id(parsed_response_body["id"])
raise "Cannot find category" unless category
@@ -112,7 +112,7 @@ def app; Categories end
assert_equal value, category[key]
end
end
-
+
test "callbacks should work" do
assert_equal "before_create after_create", parsed_response_body["log"]
end
View
34 examples/datacatalog/test/resources/categories/categories_put_test.rb
@@ -17,22 +17,22 @@ def app; Categories end
after do
@category.destroy
end
-
+
context "put /:id" do
context "anonymous" do
before do
put "/#{@category.id}", @valid_params
end
-
+
use "return 401 because the API key is missing"
use "category unchanged"
end
-
+
context "incorrect API key" do
before do
put "/#{@category.id}", @valid_params.merge(:api_key => BAD_API_KEY)
end
-
+
use "return 401 because the API key is invalid"
use "category unchanged"
end
@@ -53,7 +53,7 @@ def app; Categories end
before do
put "/#{@category.id}", valid_params_for(role).merge(invalid => 9)
end
-
+
use "return 401 because the API key is unauthorized"
use "category unchanged"
end
@@ -64,7 +64,7 @@ def app; Categories end
before do
put "/#{@category.id}", valid_params_for(role).merge(erase => "")
end
-
+
use "return 401 because the API key is unauthorized"
use "category unchanged"
end
@@ -74,7 +74,7 @@ def app; Categories end
before do
put "/#{FAKE_ID}", valid_params_for(role)
end
-
+
use "return 401 because the API key is unauthorized"
use "category unchanged"
end
@@ -83,12 +83,12 @@ def app; Categories end
before do
put "/#{@category.id}", valid_params_for(role)
end
-
+
use "return 401 because the API key is unauthorized"
use "category unchanged"
end
end
-
+
%w(curator admin).each do |role|
context "#{role} : put /:fake_id with no params" do
before do
@@ -114,7 +114,7 @@ def app; Categories end
before do
put "/#{@category.id}", valid_params_for(role).merge(invalid => 9)
end
-
+
use "return 400 Bad Request"
use "category unchanged"
invalid_param invalid
@@ -126,19 +126,19 @@ def app; Categories end
before do
put "/#{FAKE_ID}", valid_params_for(role).merge(erase => "")
end
-
+
use "return 404 Not Found with empty response body"
# (The 404 'takes precedence' over the 400.)
use "category unchanged"
end
- end
+ end
[:name].each do |erase|
context "#{role} : put /:id but blanking out #{erase}" do
before do
put "/#{@category.id}", valid_params_for(role).merge(erase => "")
end
-
+
use "return 400 Bad Request"
use "category unchanged"
missing_param erase
@@ -149,7 +149,7 @@ def app; Categories end
before do
put "/#{FAKE_ID}", valid_params_for(role)
end
-
+
use "return 404 Not Found with empty response body"
use "category unchanged"
end
@@ -158,17 +158,17 @@ def app; Categories end
before do
put "/#{@category.id}", valid_params_for(role)
end
-
+
use "return 200 Ok"
doc_properties %w(name log id created_at updated_at sources)
-
+
test "should change all fields in database" do
category = Category.find_by_id(@category.id)
@valid_params.each_pair do |key, value|
assert_equal value, category[key]
end
end
-
+
test "callbacks should work" do
assert_equal "before_update after_update", parsed_response_body["log"]
end
View
50 examples/datacatalog/test/resources/categories_sources/categories_sources_delete_test.rb
@@ -5,7 +5,7 @@ class CategoriesSourcesDeleteResourceTest < ResourceTestCase
include DataCatalog
def app; Categories end
-
+
before do
@category = create_category
@source = create_source
@@ -36,114 +36,114 @@ def app; Categories end
before do
delete "/#{@category.id}/sources/#{@source.id}"
end
-
+
use "return 401 because the API key is missing"
end
-
+
context "incorrect API key" do
before do
delete "/#{@category.id}/sources/#{@source.id}", :api_key => BAD_API_KEY
end
-
+
use "return 401 because the API key is invalid"
end
end
-
+
%w(basic).each do |role|
context "#{role} : delete /:fake_id/sources/:fake_id" do
before do
delete "/#{FAKE_ID}/sources/#{FAKE_ID}", :api_key => api_key_for(role)
end
-
+
use "return 404 Not Found with empty response body"
use "no change in source count"
end
-
+
context "#{role} : delete /:fake_id/sources/:id" do
before do
delete "/#{FAKE_ID}/sources/#{@source.id}", :api_key => api_key_for(role)
end
-
+
use "return 404 Not Found with empty response body"
use "no change in source count"
end
-
+
context "#{role} : delete /:id/sources/:fake_id" do
before do
delete "/#{@category.id}/sources/#{FAKE_ID}", :api_key => api_key_for(role)
end
-
+
use "return 401 because the API key is unauthorized"
use "no change in source count"
end
-
+
context "#{role} : delete /:id/sources/:not_related_id" do
before do
delete "/#{@category.id}/sources/#{@other_source.id}",
:api_key => api_key_for(role)
end
-
+
use "return 401 because the API key is unauthorized"
use "no change in source count"
end
-
+
context "#{role} : delete /:id/sources/:id" do
before do
delete "/#{@category.id}/sources/#{@source.id}", :api_key => api_key_for(role)
end
-
+
use "return 401 because the API key is unauthorized"
use "no change in source count"
end
end
-
+
%w(curator admin).each do |role|
context "#{role} : delete /:fake_id/sources/:fake_id" do
before do
delete "/#{FAKE_ID}/sources/#{FAKE_ID}", :api_key => api_key_for(role)
end
-
+
use "return 404 Not Found with empty response body"
use "no change in source count"
end
-
+
context "#{role} : delete /:fake_id/sources/:id" do
before do
delete "/#{FAKE_ID}/sources/#{@source.id}", :api_key => api_key_for(role)
end
-
+
use "return 404 Not Found with empty response body"
use "no change in source count"
end
-
+
context "#{role} : delete /:id/sources/:fake_id" do
before do
delete "/#{@category.id}/sources/#{FAKE_ID}", :api_key => api_key_for(role)
end
-
+
use "return 404 Not Found with empty response body"
use "no change in source count"
end
-
+
context "#{role} : delete /:id/sources/:not_related_id" do
before do
delete "/#{@category.id}/sources/#{@other_source.id}",
:api_key => api_key_for(role)
end
-
+
use "return 404 Not Found with empty response body"
use "no change in source count"
end
-
+
context "#{role} : delete /:id/sources/:id" do
before do
delete "/#{@category.id}/sources/#{@source.id}",
:api_key => api_key_for(role)
end
-
+
use "return 204 No Content"
use "one less source"
end
end
-
+
end
View
10 examples/datacatalog/test/resources/categories_sources/categories_sources_get_many_test.rb
@@ -33,7 +33,7 @@ def app; Categories end
end
@source_titles = ["Source 0", "Source 1", "Source 2"].sort
end
-
+
after do
@other_categorizations.each { |x| x.destroy }
@other_sources.each { |x| x.destroy }
@@ -48,15 +48,15 @@ def app; Categories end
before do
get "/#{@category.id}/sources"
end
-
+
use "return 401 because the API key is missing"
end
-
+
context "incorrect API key" do
before do
get "/#{@category.id}/sources", :api_key => BAD_API_KEY
end
-
+
use "return 401 because the API key is invalid"
end
end
@@ -66,7 +66,7 @@ def app; Categories end
before do
get "/#{FAKE_ID}/sources", :api_key => api_key_for(role)
end
-
+
use "return 404 Not Found with empty response body"
end
View
30 examples/datacatalog/test/resources/categories_sources/categories_sources_get_one_test.rb
@@ -5,7 +5,7 @@ class CategoriesSourcesGetOneResourceTest < ResourceTestCase
include DataCatalog
def app; Categories end
-
+
before do
@category = create_category
@source = create_source
@@ -35,61 +35,61 @@ def app; Categories end
before do
get "/#{@category.id}/sources/#{@source.id}"
end
-
+
use "return 401 because the API key is missing"
end
-
+
context "incorrect API key" do
before do
get "/#{@category.id}/sources/#{@source.id}", :api_key => BAD_API_KEY
end
-
+
use "return 401 because the API key is invalid"
end
end
-
+
%w(basic curator admin).each do |role|
context "#{role} : get /:fake_id/sources/:fake_id" do
before do
get "/#{FAKE_ID}/sources/#{FAKE_ID}", :api_key => api_key_for(role)
end
-
+
use "return 404 Not Found with empty response body"
end
-
+
context "#{role} : get /:fake_id/sources/:id" do
before do
get "/#{FAKE_ID}/sources/#{@source.id}", :api_key => api_key_for(role)
end
-
+
use "return 404 Not Found with empty response body"
end
-
+
context "#{role} : get /:id/sources/:fake_id" do
before do
get "/#{@category.id}/sources/#{FAKE_ID}", :api_key => api_key_for(role)
end
-
+
use "return 404 Not Found with empty response body"
end
-
+
context "#{role} : get /:id/sources/:not_related_id" do
before do
get "/#{@category.id}/sources/#{@other_source.id}",
:api_key => api_key_for(role)
end
-
+
use "return 404 Not Found with empty response body"
end
-
+
context "#{role} : get /:id/sources/:id" do
before do
get "/#{@category.id}/sources/#{@source.id}", :api_key => api_key_for(role)
end
-
+
use "return 200 Ok"
doc_properties %w(title url raw id created_at updated_at)
end
end
-
+
end
View
62 examples/datacatalog/test/resources/categories_sources/categories_sources_post_test.rb
@@ -5,7 +5,7 @@ class CategoriesSourcesPostResourceTest < ResourceTestCase
include DataCatalog
def app; Categories end
-
+
before do
@category = create_category
@source = create_source
@@ -20,121 +20,121 @@ def app; Categories end
}
@extra_admin_params = { :raw => { "key" => "value" } }
end
-
+
after do
@categorization.destroy
@source.destroy
@category.destroy
end
-
+
context "post /:id/sources" do
context "anonymous" do
before do
post "/#{@category.id}/sources"
end
-
+
use "return 401 because the API key is missing"
use "no change in source count"
end
-
+
context "incorrect API key" do
before do
post "/#{@category.id}/sources", :api_key => BAD_API_KEY
end
-
+
use "return 401 because the API key is invalid"
use "no change in source count"
end
end
-
+
%w(basic).each do |role|
context "#{role} : post /:fake_id/sources" do
before do
post "/#{FAKE_ID}/sources", :api_key => api_key_for(role)
end
-
+
use "return 404 Not Found with empty response body"
use "no change in source count"
end
-
+
context "#{role} : post /:id/sources" do
before do
post "/#{@category.id}/sources", :api_key => api_key_for(role)
end
-
+
use "return 401 because the API key is unauthorized"
use "no change in source count"
end
end
-
+
%w(curator).each do |role|
context "#{role} : post /:fake_id/sources" do
before do
post "/#{FAKE_ID}/sources", :api_key => api_key_for(role)
end
-
+
use "return 404 Not Found with empty response body"
use "no change in source count"
end
-
+
[:title, :url].each do |missing|
context "#{role} : post /:id/sources but missing #{missing}" do
before do
post "/#{@category.id}/sources",
valid_params_for(role).delete_if { |k, v| k == missing }
end
-
+
use "return 400 Bad Request"
use "no change in source count"
missing_param missing
end
end
-
+
[:raw, :id, :created_at, :updated_at, :junk].each do |invalid|