-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AwesomeResource now supports .create, .all, and .new methods
- Loading branch information
1 parent
aa10015
commit 033ce0b
Showing
65 changed files
with
1,510 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
*.idea | ||
fixtures/cassettes/*.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
awesome_resource |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ruby-2.0.0-p0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
source 'https://rubygems.org' | ||
|
||
gemspec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
PATH | ||
remote: . | ||
specs: | ||
awesome_resource (0.0.0) | ||
activesupport | ||
rest-client | ||
|
||
GEM | ||
remote: https://rubygems.org/ | ||
specs: | ||
actionmailer (3.2.13) | ||
actionpack (= 3.2.13) | ||
mail (~> 2.5.3) | ||
actionpack (3.2.13) | ||
activemodel (= 3.2.13) | ||
activesupport (= 3.2.13) | ||
builder (~> 3.0.0) | ||
erubis (~> 2.7.0) | ||
journey (~> 1.0.4) | ||
rack (~> 1.4.5) | ||
rack-cache (~> 1.2) | ||
rack-test (~> 0.6.1) | ||
sprockets (~> 2.2.1) | ||
activemodel (3.2.13) | ||
activesupport (= 3.2.13) | ||
builder (~> 3.0.0) | ||
activerecord (3.2.13) | ||
activemodel (= 3.2.13) | ||
activesupport (= 3.2.13) | ||
arel (~> 3.0.2) | ||
tzinfo (~> 0.3.29) | ||
activeresource (3.2.13) | ||
activemodel (= 3.2.13) | ||
activesupport (= 3.2.13) | ||
activesupport (3.2.13) | ||
i18n (= 0.6.1) | ||
multi_json (~> 1.0) | ||
addressable (2.3.4) | ||
arel (3.0.2) | ||
builder (3.0.4) | ||
crack (0.3.2) | ||
cucumber (1.3.1) | ||
builder (>= 2.1.2) | ||
diff-lcs (>= 1.1.3) | ||
gherkin (~> 2.12.0) | ||
multi_json (~> 1.3) | ||
debase (0.0.4) | ||
diff-lcs (1.1.3) | ||
erubis (2.7.0) | ||
gherkin (2.12.0) | ||
multi_json (~> 1.3) | ||
hike (1.2.2) | ||
i18n (0.6.1) | ||
journey (1.0.4) | ||
json (1.7.7) | ||
mail (2.5.3) | ||
i18n (>= 0.4.0) | ||
mime-types (~> 1.16) | ||
treetop (~> 1.4.8) | ||
mime-types (1.23) | ||
multi_json (1.7.3) | ||
polyglot (0.3.3) | ||
rack (1.4.5) | ||
rack-cache (1.2) | ||
rack (>= 0.4) | ||
rack-ssl (1.3.3) | ||
rack | ||
rack-test (0.6.2) | ||
rack (>= 1.0) | ||
rails (3.2.13) | ||
actionmailer (= 3.2.13) | ||
actionpack (= 3.2.13) | ||
activerecord (= 3.2.13) | ||
activeresource (= 3.2.13) | ||
activesupport (= 3.2.13) | ||
bundler (~> 1.0) | ||
railties (= 3.2.13) | ||
railties (3.2.13) | ||
actionpack (= 3.2.13) | ||
activesupport (= 3.2.13) | ||
rack-ssl (~> 1.3.2) | ||
rake (>= 0.8.7) | ||
rdoc (~> 3.4) | ||
thor (>= 0.14.6, < 2.0) | ||
rake (10.0.4) | ||
rdoc (3.12.2) | ||
json (~> 1.4) | ||
rest-client (1.6.7) | ||
mime-types (>= 1.16) | ||
rspec (2.12.0) | ||
rspec-core (~> 2.12.0) | ||
rspec-expectations (~> 2.12.0) | ||
rspec-mocks (~> 2.12.0) | ||
rspec-core (2.12.2) | ||
rspec-expectations (2.12.1) | ||
diff-lcs (~> 1.1.3) | ||
rspec-mocks (2.12.2) | ||
ruby-debug-ide (0.4.17.beta17) | ||
rake (>= 0.8.1) | ||
sprockets (2.2.2) | ||
hike (~> 1.2) | ||
multi_json (~> 1.0) | ||
rack (~> 1.0) | ||
tilt (~> 1.1, != 1.3.0) | ||
thor (0.18.1) | ||
tilt (1.4.0) | ||
treetop (1.4.12) | ||
polyglot | ||
polyglot (>= 0.3.1) | ||
tzinfo (0.3.37) | ||
vcr (2.4.0) | ||
webmock (1.9.3) | ||
addressable (>= 2.2.7) | ||
crack (>= 0.3.2) | ||
|
||
PLATFORMS | ||
ruby | ||
|
||
DEPENDENCIES | ||
awesome_resource! | ||
cucumber | ||
debase | ||
rails (= 3.2.13) | ||
rspec | ||
ruby-debug-ide | ||
vcr | ||
webmock (~> 1.9.0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
0.0.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
Gem::Specification.new do |s| | ||
s.author = "Matthew Kane Parker" | ||
s.version = File.read "VERSION" | ||
s.license = "Public Domain" | ||
s.name = "awesome_resource" | ||
s.summary = "An awesome implementation of ActiveResource" | ||
|
||
s.add_dependency "activesupport" | ||
s.add_dependency "rest-client" | ||
|
||
s.add_development_dependency 'cucumber' | ||
s.add_development_dependency 'rspec' | ||
s.add_development_dependency 'rails', '3.2.13' | ||
s.add_development_dependency 'vcr' | ||
s.add_development_dependency 'webmock', '~> 1.9.0' | ||
s.add_development_dependency 'debase' | ||
s.add_development_dependency 'ruby-debug-ide' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
Feature: Creating a resource | ||
|
||
Scenario: Endpoint responds with 201 | ||
Given a rails site exists accepting posts at "http://localhost:3001/articles" | ||
|
||
When I call create on an Article model: | ||
""" | ||
Article.create title: "foo" | ||
""" | ||
|
||
Then the Article model should successfully POST the following JSON to "http://localhost:3001/articles": | ||
""" | ||
{ | ||
"article": { | ||
"title": "foo" | ||
} | ||
} | ||
""" | ||
|
||
|
||
When I call the `all` method on the Article model | ||
|
||
Then the rails app should respond to a GET request to "http://localhost:3001/articles" with the following JSON: | ||
""" | ||
{ | ||
"articles": [ | ||
{ | ||
"title": "foo", | ||
"id": 1 | ||
} | ||
] | ||
} | ||
""" | ||
|
||
And the `all` method should return an array containing a single article responding to methods that correspond to the JSON properties |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
Given /^a rails site exists accepting posts at "([^"]*)"$/ do |endpoint| | ||
end | ||
|
||
When /^I call create on an Article model:$/ do |code| | ||
sleep 5; eval code | ||
end | ||
|
||
Then /^the Article model should successfully POST the following JSON to "([^"]*)":$/ do |endpoint, json| | ||
posts.should include_request endpoint, json | ||
end | ||
|
||
When /^I call the `all` method on the Article model$/ do | ||
@all = Article.all | ||
end | ||
|
||
Then /^the rails app should respond to a GET request to "([^"]*)" with the following JSON:$/ do |endpoint, json| | ||
gets.should include_response endpoint, json | ||
end | ||
|
||
When /^the `all` method should return an array containing a single article responding to methods that correspond to the JSON properties$/ do | ||
@all.first.id.should == 1 | ||
@all.first.title.should == "foo" | ||
end | ||
|
||
def gets | ||
interactions[:get] ||= [] | ||
end | ||
|
||
def posts | ||
interactions[:post] ||= [] | ||
end | ||
|
||
RSpec::Matchers.define :include_response do |endpoint, json| | ||
match do |http_interactions| | ||
http_interactions.any? do |interaction| | ||
interaction[:request].uri.to_s == endpoint && | ||
JSON.parse(interaction[:response].body).should == JSON.parse(json) | ||
end | ||
end | ||
end | ||
|
||
RSpec::Matchers.define :include_request do |endpoint, json| | ||
match do |http_interactions| | ||
http_interactions.any? do |interaction| | ||
interaction[:request].uri.to_s == endpoint && | ||
JSON.parse(interaction[:request].body).should == JSON.parse(json) | ||
end | ||
end | ||
end | ||
|
||
def interactions | ||
Interactions.interactions | ||
end | ||
|
||
|
||
Before do | ||
Interactions.reset! | ||
stop_server | ||
start_server | ||
end | ||
|
||
def start_server | ||
Bundler.with_clean_env do | ||
raise "couldn't start server" unless system "RAILS_ENV=development cd fixtures/server && rake db:reset && bundle exec thin start -C config/thin.yml" | ||
end | ||
end | ||
|
||
def stop_server | ||
Bundler.with_clean_env do | ||
system "RAILS_ENV=development cd fixtures/server && bundle exec thin stop -C config/thin.yml" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
$LOAD_PATH.unshift "./lib" | ||
|
||
require 'awesome_resource' | ||
|
||
require 'rspec/expectations' | ||
World(RSpec::Matchers) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class Article | ||
include AwesomeResource | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
require 'vcr' | ||
module Interactions | ||
extend self | ||
|
||
def interactions | ||
@interactions ||= {} | ||
end | ||
|
||
def reset! | ||
@interactions = nil | ||
end | ||
end | ||
|
||
VCR.configure do |c| | ||
c.hook_into :webmock | ||
c.cassette_library_dir = 'fixtures/cassettes' | ||
c.default_cassette_options = { :record => :all } | ||
|
||
c.after_http_request(->(_){ true }) do |request, response| | ||
Interactions.interactions[request.method] ||= [] | ||
Interactions.interactions[request.method] << {request: request, response: response} | ||
end | ||
end | ||
|
||
Before do |scenario| | ||
VCR.insert_cassette scenario.name, record: :all | ||
end | ||
|
||
After do | ||
VCR.eject_cassette | ||
end |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# See http://help.github.com/ignore-files/ for more about ignoring files. | ||
# | ||
# If you find yourself ignoring temporary files generated by your text editor | ||
# or operating system, you probably want to add a global ignore instead: | ||
# git config --global core.excludesfile ~/.gitignore_global | ||
|
||
# Ignore bundler config | ||
/.bundle | ||
|
||
# Ignore the default SQLite database. | ||
/db/*.sqlite3 | ||
|
||
# Ignore all logfiles and tempfiles. | ||
/log/*.log | ||
/tmp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
source 'https://rubygems.org' | ||
|
||
gem 'rails', '3.2.13' | ||
|
||
# Bundle edge Rails instead: | ||
# gem 'rails', :git => 'git://github.com/rails/rails.git' | ||
|
||
gem 'active_model_serializers' | ||
gem 'sqlite3' | ||
gem 'thin' | ||
gem 'ruby-debug-ide' | ||
gem 'debase' | ||
|
||
# Gems used only for assets and not required | ||
# in production environments by default. | ||
group :assets do | ||
gem 'sass-rails', '~> 3.2.3' | ||
gem 'coffee-rails', '~> 3.2.1' | ||
|
||
# See https://github.com/sstephenson/execjs#readme for more supported runtimes | ||
# gem 'therubyracer', :platforms => :ruby | ||
|
||
gem 'uglifier', '>= 1.0.3' | ||
end |
Oops, something went wrong.