Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
137 additions
and
3 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
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
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
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,5 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
module Zyra | ||
VERSION = '0.0.2' | ||
VERSION = '1.0.0' | ||
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,54 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
|
||
describe Zyra do | ||
describe 'readme' do | ||
it 'registering a model' do | ||
Zyra | ||
.register(User, find_by: :email) | ||
.on(:build) do |user| | ||
user.reference = SecureRandom.hex(16) | ||
end | ||
|
||
attributes = { | ||
email: 'usr@srv.com', | ||
name: 'Some User', | ||
password: 'pass' | ||
} | ||
|
||
user = Zyra.find_or_create(:user, attributes) do |usr| | ||
usr.update(attributes) | ||
end | ||
|
||
expect(user.name).to eq('Some User') | ||
expect(user.email).to eq('usr@srv.com') | ||
expect(user.password).to eq('pass') | ||
expect(user.reference).not_to be_nil | ||
end | ||
|
||
it 'Registering hooks' do | ||
Zyra | ||
.register(User, find_by: :email) | ||
.on(:build) do |user| | ||
user.posts.build(name: 'first', content: 'some content') | ||
end | ||
|
||
Zyra.on(:user, :return) do |user| | ||
user.update(reference: SecureRandom.hex(16)) | ||
end | ||
|
||
attributes = { | ||
email: 'usr@srv.com', | ||
name: 'Some User', | ||
password: 'pass' | ||
} | ||
|
||
user = Zyra.find_or_create(:user, attributes).reload | ||
|
||
expect(user.email).to eq('usr@srv.com') | ||
expect(user.posts).not_to be_empty | ||
expect(user.reference).not_to be_nil | ||
end | ||
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,5 @@ | ||
# frozen_string_literal: true | ||
|
||
class Post < ActiveRecord::Base | ||
belongs_to :user | ||
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
class User < ActiveRecord::Base | ||
has_many :posts | ||
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