Permalink
Browse files

renaming to ember-resource

  • Loading branch information...
1 parent 541886a commit 5647e66ba0707d02abde002384c3e7f4e10cb9cc @staugaard committed Dec 16, 2011
View
@@ -1,10 +1,10 @@
-# SproutCore-Resource [![Build Status](https://secure.travis-ci.org/staugaard/sproutcore-resource.png)](http://travis-ci.org/staugaard/sproutcore-resource)
+# Ember-Resource [![Build Status](https://secure.travis-ci.org/staugaard/ember-resource.png)](http://travis-ci.org/staugaard/ember-resource)
-A simple library to connect your SproutCore 2.0 application to JSON backends.
+A simple library to connect your Ember.js application to JSON backends.
## The Mandatory Todo Appplication
-I've created a modified version of the todo application that the SproutCore 2.0 Tutorial walks you through.
+I've created a modified version of the todo application that the Ember.js Tutorial walks you through.
https://github.com/staugaard/sproutcore-resource-todos
This version persists the todo items on the server using a very small sinatra application and MongoDB.
@@ -26,13 +26,13 @@ Assuming that /users/1 returns this JSON:
You would use this user model:
```javascript
-MyApp.User = SC.Resource.define({
+MyApp.User = Ember.Resource.define({
url: '/users',
schema: {
id: Number,
name: String,
blogs: {
- type: SC.ResourceCollection,
+ type: Ember.ResourceCollection,
itemType: 'MyApp.Blog',
url: '/users/%@/blogs'
}
@@ -53,7 +53,7 @@ Assuming that /blogs/1 returns this JSON:
You would use this blog model:
```javascript
-MyApp.Blog = SC.Resource.define({
+MyApp.Blog = Ember.Resource.define({
url: '/blogs'
schema: {
id: Number,
@@ -62,7 +62,7 @@ MyApp.Blog = SC.Resource.define({
type: MyApp.User
},
posts: {
- type: SC.ResourceCollection,
+ type: Ember.ResourceCollection,
itemType: 'MyApp.Post',
url: '/blogs/%@/posts'
}
@@ -84,7 +84,7 @@ Assuming that /posts/1 returns this JSON:
You would use this post model:
```javascript
-MyApp.Post = SC.Resource.define({
+MyApp.Post = Ember.Resource.define({
url: '/posts',
schema: {
id: Number,
@@ -94,7 +94,7 @@ MyApp.Post = SC.Resource.define({
type: MyApp.Blog
},
comments: {
- type: SC.ResourceCollection,
+ type: Ember.ResourceCollection,
itemType: 'MyApp.Comment',
url: '/posts/%@/comments'
}
@@ -119,7 +119,7 @@ Assuming that /comments/1 returns this JSON:
You would use this comment model:
```javascript
-MyApp.Comment = SC.Resource.define({
+MyApp.Comment = Ember.Resource.define({
url: '/comments',
schema: {
id: Number,
View
@@ -52,7 +52,7 @@ indent: 2 # Number of spaces that should be used for indentation - use
maxerr: 50 # The maximum number of warnings reported (per file)
passfail: false # true if the scan should stop on first error (per file)
# following are relevant only if undef = true
-predef: '$,SC,jasmine,describe,beforeEach,it,afterEach,expect,spyOn,runs,waits,waitsFor,sinon' # Names of predefined global variables - comma-separated string or a YAML array
+predef: '$,Ember,SC,jasmine,describe,beforeEach,it,afterEach,expect,spyOn,runs,waits,waitsFor,sinon' # Names of predefined global variables - comma-separated string or a YAML array
browser: true # true if the standard browser globals should be predefined
rhino: false # true if the Rhino environment globals should be predefined
windows: false # true if Windows-specific globals should be predefined
@@ -1,5 +1,5 @@
describe('associations', function() {
- var Address = SC.Resource.define({
+ var Address = Ember.Resource.define({
schema: {
id: Number,
street: String,
@@ -28,7 +28,7 @@ describe('associations', function() {
});
it('should use embedded data', function() {
- var Person = SC.Resource.define({
+ var Person = Ember.Resource.define({
schema: {
name: String,
address: {type: Address, nested: true}
@@ -48,7 +48,7 @@ describe('associations', function() {
});
it('should support path overriding', function() {
- var Person = SC.Resource.define({
+ var Person = Ember.Resource.define({
schema: {
name: String,
address: {type: Address, nested: true, path: 'addresses.home'}
@@ -71,7 +71,7 @@ describe('associations', function() {
});
it('should have an id accessor', function() {
- var Person = SC.Resource.define({
+ var Person = Ember.Resource.define({
schema: {
name: String,
address: {type: Address, nested: true}
@@ -100,17 +100,17 @@ describe('associations', function() {
describe('with url', function() {
beforeEach(function() {
- Person = SC.Resource.define({
+ Person = Ember.Resource.define({
schema: {
id: Number,
name: String,
home_addresses: {
- type: SC.ResourceCollection,
+ type: Ember.ResourceCollection,
itemType: Address,
url: '/people/%@/addresses'
},
work_addresses: {
- type: SC.ResourceCollection,
+ type: Ember.ResourceCollection,
itemType: Address,
url: function(instance) {
return '/people/' + instance.get('id') + '/addresses';
@@ -125,7 +125,7 @@ describe('associations', function() {
var homeAddresses = person.get('home_addresses');
expect(homeAddresses).toBeDefined();
- expect(homeAddresses instanceof SC.ResourceCollection).toBe(true);
+ expect(homeAddresses instanceof Ember.ResourceCollection).toBe(true);
expect(homeAddresses.type).toBe(Address);
expect(homeAddresses.url).toBe('/people/1/addresses');
});
@@ -135,24 +135,24 @@ describe('associations', function() {
var workAddresses = person.get('work_addresses');
expect(workAddresses).toBeDefined();
- expect(workAddresses instanceof SC.ResourceCollection).toBe(true);
+ expect(workAddresses instanceof Ember.ResourceCollection).toBe(true);
expect(workAddresses.type).toBe(Address);
expect(workAddresses.url).toBe('/people/1/addresses');
});
});
describe('nested', function() {
beforeEach(function() {
- Person = SC.Resource.define({
+ Person = Ember.Resource.define({
schema: {
name: String,
home_addresses: {
- type: SC.ResourceCollection,
+ type: Ember.ResourceCollection,
itemType: Address,
nested: true
},
work_addresses: {
- type: SC.ResourceCollection,
+ type: Ember.ResourceCollection,
itemType: Address,
nested: true,
path: 'office_addresses'
@@ -180,7 +180,7 @@ describe('associations', function() {
var homeAddresses = person.get('home_addresses');
expect(homeAddresses).toBeDefined();
- expect(homeAddresses instanceof SC.ResourceCollection).toBe(true);
+ expect(homeAddresses instanceof Ember.ResourceCollection).toBe(true);
expect(homeAddresses.type).toBe(Address);
expect(homeAddresses.get('length')).toBe(2);
@@ -221,11 +221,11 @@ describe('associations', function() {
describe('in array', function() {
beforeEach(function() {
- Person = SC.Resource.define({
+ Person = Ember.Resource.define({
schema: {
name: String,
home_addresses: {
- type: SC.ResourceCollection,
+ type: Ember.ResourceCollection,
itemType: Address,
path: 'home_address_ids'
}
@@ -2,7 +2,7 @@ describe('Auto fetching', function() {
var Person, server;
beforeEach(function() {
- Person = SC.Resource.define({
+ Person = Ember.Resource.define({
url: '/people',
schema: {
id: Number,
@@ -11,7 +11,7 @@ describe('Auto fetching', function() {
});
server = sinon.fakeServer.create();
- SC.Resource.Lifecycle.clock.tick();
+ Ember.Resource.Lifecycle.clock.tick();
});
afterEach(function() {
@@ -62,13 +62,13 @@ describe('Auto fetching', function() {
server.respondWith("GET", "/people",
[200, { "Content-Type": "application/json" },
'[{ "id": 1, "name": "Mick Staugaard" }]']);
- people = SC.ResourceCollection.create({type: Person});
+ people = Ember.ResourceCollection.create({type: Person});
server.respond();
});
it('should not fetch on creation', function() {
var hasFetched = false;
- var TestCollection = SC.ResourceCollection.extend({
+ var TestCollection = Ember.ResourceCollection.extend({
fetch: function() {
hasFetched = true;
}
@@ -1,31 +1,31 @@
describe('deepMerge', function() {
it('should add missing keys', function() {
var obj = {};
- SC.Resource.deepMerge(obj, {a: 'foo'});
+ Ember.Resource.deepMerge(obj, {a: 'foo'});
expect(obj.a).toBeDefined();
expect(obj.a).toBe('foo');
});
it('should override keys', function() {
var obj = {a: 'foo'};
- SC.Resource.deepMerge(obj, {a: 'bar'});
+ Ember.Resource.deepMerge(obj, {a: 'bar'});
expect(obj.a).toBeDefined();
expect(obj.a).toBe('bar');
});
it('should leave other keys', function() {
var obj = {a: 'foo'};
- SC.Resource.deepMerge(obj, {b: 'bar'});
+ Ember.Resource.deepMerge(obj, {b: 'bar'});
expect(obj.a).toBeDefined();
expect(obj.a).toBe('foo');
});
it('merge recursively', function() {
var obj = {a: {b: 'foo'}};
- SC.Resource.deepMerge(obj, {a: {b: 'bar'}});
+ Ember.Resource.deepMerge(obj, {a: {b: 'bar'}});
expect(obj.a.b).toBeDefined();
expect(obj.a.b).toBe('bar');
@@ -1,29 +1,29 @@
describe('deepSet', function() {
it('should set at the given path', function() {
var obj = {};
- SC.Resource.deepSet(obj, 'a', 'foo');
+ Ember.Resource.deepSet(obj, 'a', 'foo');
expect(obj.a).toBeDefined();
expect(obj.a).toBe('foo');
});
it('should overwrite at the given path', function() {
var obj = {a: 'foo'};
- SC.Resource.deepSet(obj, 'a', 'bar');
+ Ember.Resource.deepSet(obj, 'a', 'bar');
expect(obj.a).toBeDefined();
expect(obj.a).toBe('bar');
});
it('should create empty Object at missing nodes', function() {
var obj = {};
- SC.Resource.deepSet(obj, 'a.b.c', 'foo');
+ Ember.Resource.deepSet(obj, 'a.b.c', 'foo');
expect(obj.a).toBeDefined();
- expect(SC.typeOf(obj.a)).toBe('object');
+ expect(Ember.typeOf(obj.a)).toBe('object');
expect(obj.a.b).toBeDefined();
- expect(SC.typeOf(obj.a.b)).toBe('object');
+ expect(Ember.typeOf(obj.a.b)).toBe('object');
expect(obj.a.b.c).toBeDefined();
expect(obj.a.b.c).toBe('foo');
@@ -10,7 +10,7 @@ describe('Inheritance', function() {
};
beforeEach(function() {
- Person = SC.Resource.define({
+ Person = Ember.Resource.define({
url: '/people',
schema: {
id: Number,
@@ -2,7 +2,7 @@ describe('Lifecycle', function() {
var Person, server;
beforeEach(function() {
- Person = SC.Resource.define({
+ Person = Ember.Resource.define({
url: '/people',
schema: {
id: Number,
@@ -27,7 +27,7 @@ describe('Lifecycle', function() {
});
it('should be in the UNFETCHED state', function() {
- expect(person.get('resourceState')).toBe(SC.Resource.Lifecycle.UNFETCHED);
+ expect(person.get('resourceState')).toBe(Ember.Resource.Lifecycle.UNFETCHED);
});
it('should not be expired', function() {
@@ -51,7 +51,7 @@ describe('Lifecycle', function() {
});
it('should put the object in a FETCHING state', function() {
- expect(person.get('resourceState')).toBe(SC.Resource.Lifecycle.FETCHING);
+ expect(person.get('resourceState')).toBe(Ember.Resource.Lifecycle.FETCHING);
});
describe('is done', function() {
@@ -60,7 +60,7 @@ describe('Lifecycle', function() {
});
it('should put the object in a FETCHED state when the fetch is done', function() {
- expect(person.get('resourceState')).toBe(SC.Resource.Lifecycle.FETCHED);
+ expect(person.get('resourceState')).toBe(Ember.Resource.Lifecycle.FETCHED);
});
it('should set expiry in 5 minutes', function() {
@@ -79,23 +79,23 @@ describe('Lifecycle', function() {
beforeEach(function() {
person = Person.create({id: 1});
- SC.Resource.Lifecycle.clock.tick();
+ Ember.Resource.Lifecycle.clock.tick();
});
it('should be expired with an expireAt in the past', function() {
var expiry = new Date();
expiry.setFullYear(expiry.getFullYear() - 1);
person.set('expireAt', expiry);
expect(person.get('isExpired')).toBe(true);
- expect(person.get('resourceState')).toBe(SC.Resource.Lifecycle.EXPIRED);
+ expect(person.get('resourceState')).toBe(Ember.Resource.Lifecycle.EXPIRED);
});
it('should be expired with an expireAt in the future', function() {
var expiry = new Date();
expiry.setFullYear(expiry.getFullYear() + 1);
person.set('expireAt', expiry);
expect(person.get('isExpired')).toBe(false);
- expect(person.get('resourceState')).toBe(SC.Resource.Lifecycle.UNFETCHED);
+ expect(person.get('resourceState')).toBe(Ember.Resource.Lifecycle.UNFETCHED);
});
it('should expire when "expire" is called', function() {
Oops, something went wrong.

0 comments on commit 5647e66

Please sign in to comment.