From f96ddba7173c9c1ce287ad71eef387eb04c293e8 Mon Sep 17 00:00:00 2001 From: Ilion Beyst Date: Tue, 8 Sep 2015 11:30:11 +0200 Subject: [PATCH] generate models --- app/models/client.rb | 2 + app/models/transaction.rb | 4 ++ app/models/user.rb | 6 +++ config/routes.rb | 1 + .../20150908091028_devise_create_users.rb | 45 +++++++++++++++++++ .../20150908091546_create_transactions.rb | 13 ++++++ db/migrate/20150908092731_create_clients.rb | 10 +++++ spec/factories/clients.rb | 7 +++ spec/factories/transactions.rb | 10 +++++ spec/factories/users.rb | 6 +++ spec/models/client_spec.rb | 5 +++ spec/models/transaction_spec.rb | 5 +++ spec/models/user_spec.rb | 5 +++ 13 files changed, 119 insertions(+) create mode 100644 app/models/client.rb create mode 100644 app/models/transaction.rb create mode 100644 app/models/user.rb create mode 100644 db/migrate/20150908091028_devise_create_users.rb create mode 100644 db/migrate/20150908091546_create_transactions.rb create mode 100644 db/migrate/20150908092731_create_clients.rb create mode 100644 spec/factories/clients.rb create mode 100644 spec/factories/transactions.rb create mode 100644 spec/factories/users.rb create mode 100644 spec/models/client_spec.rb create mode 100644 spec/models/transaction_spec.rb create mode 100644 spec/models/user_spec.rb diff --git a/app/models/client.rb b/app/models/client.rb new file mode 100644 index 0000000..998b2e4 --- /dev/null +++ b/app/models/client.rb @@ -0,0 +1,2 @@ +class Client < ActiveRecord::Base +end diff --git a/app/models/transaction.rb b/app/models/transaction.rb new file mode 100644 index 0000000..80ca2f0 --- /dev/null +++ b/app/models/transaction.rb @@ -0,0 +1,4 @@ +class Transaction < ActiveRecord::Base + belongs_to :debtor + belongs_to :creditor +end diff --git a/app/models/user.rb b/app/models/user.rb new file mode 100644 index 0000000..c822027 --- /dev/null +++ b/app/models/user.rb @@ -0,0 +1,6 @@ +class User < ActiveRecord::Base + # Include default devise modules. Others available are: + # :confirmable, :lockable, :timeoutable and :omniauthable + devise :database_authenticatable, :registerable, + :recoverable, :rememberable, :trackable, :validatable +end diff --git a/config/routes.rb b/config/routes.rb index 3f66539..fc2791d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,5 @@ Rails.application.routes.draw do + devise_for :users # The priority is based upon order of creation: first created -> highest priority. # See how all your routes lay out with "rake routes". diff --git a/db/migrate/20150908091028_devise_create_users.rb b/db/migrate/20150908091028_devise_create_users.rb new file mode 100644 index 0000000..c519be3 --- /dev/null +++ b/db/migrate/20150908091028_devise_create_users.rb @@ -0,0 +1,45 @@ +class DeviseCreateUsers < ActiveRecord::Migration + def change + create_table(:users) do |t| + ## Database authenticatable + t.string :email, null: false, default: "" + t.string :encrypted_password, null: false, default: "" + + ## Recoverable + t.string :reset_password_token + t.datetime :reset_password_sent_at + + ## Rememberable + t.datetime :remember_created_at + + ## Trackable + t.integer :sign_in_count, default: 0, null: false + t.datetime :current_sign_in_at + t.datetime :last_sign_in_at + t.string :current_sign_in_ip + t.string :last_sign_in_ip + + ## Confirmable + # t.string :confirmation_token + # t.datetime :confirmed_at + # t.datetime :confirmation_sent_at + # t.string :unconfirmed_email # Only if using reconfirmable + + ## Lockable + # t.integer :failed_attempts, default: 0, null: false # Only if lock strategy is :failed_attempts + # t.string :unlock_token # Only if unlock strategy is :email or :both + # t.datetime :locked_at + + t.string :name + t.integer :balance + t.boolean :penning + + t.timestamps null: false + end + + add_index :users, :email, unique: true + add_index :users, :reset_password_token, unique: true + # add_index :users, :confirmation_token, unique: true + # add_index :users, :unlock_token, unique: true + end +end diff --git a/db/migrate/20150908091546_create_transactions.rb b/db/migrate/20150908091546_create_transactions.rb new file mode 100644 index 0000000..4ce3de6 --- /dev/null +++ b/db/migrate/20150908091546_create_transactions.rb @@ -0,0 +1,13 @@ +class CreateTransactions < ActiveRecord::Migration + def change + create_table :transactions do |t| + t.references :debtor, index: true, foreign_key: true + t.references :creditor, index: true, foreign_key: true + t.integer :amount + t.string :origin + t.string :message + + t.timestamps null: false + end + end +end diff --git a/db/migrate/20150908092731_create_clients.rb b/db/migrate/20150908092731_create_clients.rb new file mode 100644 index 0000000..dcc340a --- /dev/null +++ b/db/migrate/20150908092731_create_clients.rb @@ -0,0 +1,10 @@ +class CreateClients < ActiveRecord::Migration + def change + create_table :clients do |t| + t.string :name + t.string :key + + t.timestamps null: false + end + end +end diff --git a/spec/factories/clients.rb b/spec/factories/clients.rb new file mode 100644 index 0000000..acf9478 --- /dev/null +++ b/spec/factories/clients.rb @@ -0,0 +1,7 @@ +FactoryGirl.define do + factory :client do + name "MyString" +key "MyString" + end + +end diff --git a/spec/factories/transactions.rb b/spec/factories/transactions.rb new file mode 100644 index 0000000..9561b45 --- /dev/null +++ b/spec/factories/transactions.rb @@ -0,0 +1,10 @@ +FactoryGirl.define do + factory :transaction do + debtor nil +creditor nil +amount 1 +origin "MyString" +message "MyString" + end + +end diff --git a/spec/factories/users.rb b/spec/factories/users.rb new file mode 100644 index 0000000..209e6b1 --- /dev/null +++ b/spec/factories/users.rb @@ -0,0 +1,6 @@ +FactoryGirl.define do + factory :user do + + end + +end diff --git a/spec/models/client_spec.rb b/spec/models/client_spec.rb new file mode 100644 index 0000000..2e2c38a --- /dev/null +++ b/spec/models/client_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe Client, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/transaction_spec.rb b/spec/models/transaction_spec.rb new file mode 100644 index 0000000..572759a --- /dev/null +++ b/spec/models/transaction_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe Transaction, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb new file mode 100644 index 0000000..47a31bb --- /dev/null +++ b/spec/models/user_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe User, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +end