12-oz/pliny — pull request #51 by brandur (2014-04-21 02:49:01+00:00)
Title: JSON Schema-compliant scaffolding

Generates a full scaffold for a new entity:

```
$ bundle exec pliny-generate scaffold artists
created endpoint file ./lib/endpoints/artists.rb
add the following to lib/routes.rb:
use Endpoints::Artists
created test ./test/endpoints/artists_test.rb
created test ./test/acceptance/artists_test.rb
created model file ./lib/models/artists.rb
created migration ./db/migrate/1398048122_create_artists.rb
created test ./test/models/artists_test.rb
created schema file ./docs/schema/schemata/artist.json
rebuilt ./docs/schema.json
```

Scaffolded endpoints have some basic functionality built into them like the Rails equivalent:

``` ruby
class Artists < Base
namespace "/artists" do
before do
content_type :json
end

get do
MultiJson.encode Artist.all.map { |x| serialize(x) }
end

...
end
```

Scaffolded acceptance tests check JSON Schema compliance using a Direwolf-like `assert_schema_conform` which I've recently pulled into Committee:

``` ruby
it "GET /artists" do
get "/artists"
assert_equal 200, last_response.status
assert_schema_conform
end
```

A database migration needs to be run (hopefully we can pull this into the scaffolding function as well), but after it is, we get passing tests right away (the schemata is rebuilt by the generator):

```
$ rake
Run options: --seed 21072

# Running:

...

Finished in 0.047217s, 63.5364 runs/s, 63.5364 assertions/s.

3 runs, 3 assertions, 0 failures, 0 errors, 0 skips
```

There are a few things left to do, but I'll probably leave them to other pulls:

* Scaffold mediators.
* Bring in acceptance tests for the full set of scaffolded endpoints.