-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added test cases for save and create
- Loading branch information
Showing
17 changed files
with
139 additions
and
11 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 |
---|---|---|
|
@@ -6,3 +6,4 @@ test/dummy/db/*.sqlite3-journal | |
test/dummy/log/*.log | ||
test/dummy/tmp/ | ||
test/dummy/.sass-cache | ||
.byebug_history |
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
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,2 @@ | ||
class EmployeeDetail < ActiveRecord::Base | ||
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,4 @@ | ||
class Profile < ActiveRecord::Base | ||
# belongs_to :user | ||
has_subclass :employee_detail | ||
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,4 @@ | ||
class User < ActiveRecord::Base | ||
has_subclass :profile | ||
has_subclass :user_preference | ||
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,2 @@ | ||
class UserPreference < ActiveRecord::Base | ||
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
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 @@ | ||
require 'mti' | ||
|
||
ActiveRecord::Base.class_eval do | ||
include Mti | ||
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,8 @@ | ||
class CreateUsers < ActiveRecord::Migration[5.2] | ||
def change | ||
create_table :users do |t| | ||
t.string :email | ||
t.string :password | ||
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,9 @@ | ||
class CreateProfiles < ActiveRecord::Migration[5.2] | ||
def change | ||
create_table :profiles do |t| | ||
t.references :user, index: true | ||
t.string :name | ||
t.text :address | ||
end | ||
end | ||
end |
8 changes: 8 additions & 0 deletions
8
test/dummy/db/migrate/20181117110520_create_user_preferences.rb
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,8 @@ | ||
class CreateUserPreferences < ActiveRecord::Migration[5.2] | ||
def change | ||
create_table :user_preferences do |t| | ||
t.references :user, index: true | ||
t.string :hobbies | ||
end | ||
end | ||
end |
8 changes: 8 additions & 0 deletions
8
test/dummy/db/migrate/20181117110530_create_employee_detail.rb
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,8 @@ | ||
class CreateEmployeeDetail < ActiveRecord::Migration[5.2] | ||
def change | ||
create_table :employee_details do |t| | ||
t.references :profile, index: true | ||
t.string :emp_id | ||
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,39 @@ | ||
# This file is auto-generated from the current state of the database. Instead | ||
# of editing this file, please use the migrations feature of Active Record to | ||
# incrementally modify your database, and then regenerate this schema definition. | ||
# | ||
# Note that this schema.rb definition is the authoritative source for your | ||
# database schema. If you need to create the application database on another | ||
# system, you should be using db:schema:load, not running all the migrations | ||
# from scratch. The latter is a flawed and unsustainable approach (the more migrations | ||
# you'll amass, the slower it'll run and the greater likelihood for issues). | ||
# | ||
# It's strongly recommended that you check this file into your version control system. | ||
|
||
ActiveRecord::Schema.define(version: 2018_11_17_110530) do | ||
|
||
create_table "employee_details", force: :cascade do |t| | ||
t.integer "profile_id" | ||
t.string "emp_id" | ||
t.index ["profile_id"], name: "index_employee_details_on_profile_id" | ||
end | ||
|
||
create_table "profiles", force: :cascade do |t| | ||
t.integer "user_id" | ||
t.string "name" | ||
t.text "address" | ||
t.index ["user_id"], name: "index_profiles_on_user_id" | ||
end | ||
|
||
create_table "user_preferences", force: :cascade do |t| | ||
t.integer "user_id" | ||
t.string "hobbies" | ||
t.index ["user_id"], name: "index_user_preferences_on_user_id" | ||
end | ||
|
||
create_table "users", force: :cascade do |t| | ||
t.string "email" | ||
t.string "password" | ||
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 |
---|---|---|
@@ -1,7 +1,30 @@ | ||
require 'test_helper' | ||
|
||
class MtiTest < ActiveSupport::TestCase | ||
test "truth" do | ||
assert_kind_of Module, Mti | ||
|
||
def setup | ||
@user_params = { | ||
email: 'dummy@test.com', | ||
name: 'dummy', | ||
address: 'dummy address', | ||
hobbies: 'nothing' | ||
} | ||
@profile_params = { | ||
emp_id: 'E01' | ||
} | ||
end | ||
|
||
test "for create method" do | ||
user = User.create(@user_params) | ||
user.profile.emp_id = @profile_params[:emp_id] | ||
user.save | ||
assert_equal(@user_params.values + @profile_params.values, [user.email, user.name, user.address, user.hobbies, user.profile.emp_id], 'Something went wrong while creating') | ||
end | ||
|
||
test "for save method" do | ||
user = User.new(@user_params) | ||
user.profile.emp_id = @profile_params[:emp_id] | ||
user.save | ||
assert_equal(@user_params.values + @profile_params.values, [user.email, user.name, user.address, user.hobbies, user.profile.emp_id], 'Something went wrong while saving') | ||
end | ||
end |