Skip to content

Commit

Permalink
intrudocing the .create() method
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielfalcao committed Aug 31, 2015
1 parent a4a0436 commit 9f57958
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
9 changes: 9 additions & 0 deletions repocket/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,15 @@ def __eq__(self, other):

return self.to_dict() == other.to_dict()

@classmethod
def create(cls, **kwargs):
"""Takes all the valid attributes of an active record, saves it
immediately and returns the instance, ready for further manipulation.
"""
item = cls(**kwargs)
item.save()
return item

@classmethod
def _static_key_prefix(cls):
return b'repocket:{0}:{1}'.format(
Expand Down
19 changes: 19 additions & 0 deletions tests/functional/test_active_record.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,3 +244,22 @@ def test_get_retrieving_reference(context):
result.should.equal(post)

post.author.should.equal(author)


@clean_slate
def test_create_user(context):
('ActiveRecord.create() should store the the fields successfully in a hash')

# Given that I instantiate create a user
result = User.create(
access_token=b'sometoken',
email='foo@bar.com',
github_metadata={
'yay': 'this is json baby!'
}
)

result.should.be.a(User)

found = User.objects.get(id=result.id)
found.should.equal(result)

0 comments on commit 9f57958

Please sign in to comment.