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
import XCTest | |
class UserRepoTests: XCTestCase { | |
var userRepo = UserRepo() | |
var email = "user@gmail.com" | |
var result = [User]() | |
override func setUp() { | |
super.setUp() | |
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
import XCTest | |
class UserRepoRefactoredTests: XCTestCase { | |
var userRepo = UserRepo() | |
var email = "user@gmail.com" | |
var result = [User]() | |
lazy var findAdminsByAction: Action = { | |
return Action() { | |
self.createAdmin(name: "User Admin 1") |
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
import Quick | |
import Nimble | |
class UserRepoTest: QuickSpec { | |
override func spec() { | |
var userRepo = UserRepo() | |
describe("#findAdminsBy") { |
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
import Foundation | |
struct Action { | |
let block: () -> () | |
func call() { | |
block() | |
} | |
} |
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
# If Else Statment | |
def render_msg(state) | |
if state == :in_progress | |
return 'In Progress' | |
elsif state == :done | |
return 'Done' | |
elsif state == :on_review | |
return 'On Review' | |
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
def render_msg(state) | |
state_msgs = { | |
in_progress: 'In Progress', | |
done: 'Done', | |
on_review: 'On Review' | |
} | |
state_msgs[state] | |
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
def extract_params(state, params) | |
if state == :in_progress | |
return params.select { |k, v| [:key_a, :key_b].include?(k) } | |
elsif state == :done | |
return params.select { |k, v| [:key_c, :key_d].include?(k) } | |
elsif state == :on_review | |
return params.select { |k, v| [:key_e, :key_f].include?(k) } | |
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
def extract_params(state, params) | |
state_keys = { | |
in_progress: %I[key_a key_b], | |
done: %I[key_c key_d], | |
on_review: %I[key_e key_f] | |
} | |
params.select { |k, v| state_keys[state].include?(k) } | |
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
def save(state, params) | |
if state == :in_progress | |
return save_in_progress(params) | |
elsif state == :done | |
return save_done(params) | |
elsif state == :on_review | |
return save_on_review(params) | |
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
def save(state, params) | |
state_action = { | |
in_progress: :save_in_progress, | |
done: :save_done, | |
on_review: :save_on_review | |
} | |
action = state_action[state] | |
self.send(action, params) | |
end |
OlderNewer