Skip to content

Instantly share code, notes, and snippets.

View somethvictory's full-sized avatar

Someth Victory somethvictory

View GitHub Profile
@somethvictory
somethvictory / catalog.rb
Created January 7, 2022 08:48
catalog.rb
class Catalog < ApplicationRecord
has_many :rewards
has_many :campaigns
end
{"data":
{"id":1,
"name":"Miss Rikki Parisian",
"description":"Davis Runolfsdottir",
"terms_and_conditions":null,
"partner":null,
"begins_at":"2020-02-05T00:00:00.000Z",
"ends_at":"2020-02-13T00:00:00.000Z",
"ordering":1,
"images":[],
@somethvictory
somethvictory / reverse_number.rb
Last active January 18, 2019 09:36
Reverse number algorithm in pure Ruby. No string and array methods which are related to the ordering is allowed.
# reverse_number(12345)
# => 54321
def reverse_number(number)
raise 'Input must be number' unless number.is_a? Numeric
reversed_numbers = []
# do the operation until all the numbers are modulused and divided
loop do
# modulus by 10 to get the remaining and add them to the reverse_numbers array
reversed_numbers << number % 10
require 'rails_helper'
RSpec.feature 'Dashboard', type: :feature, js: true do
let!(:robot1) { FactoryBot.create(:robot, :qa_passed) }
let!(:robot2) { FactoryBot.create(:robot, :factory_second) }
let!(:robot3) { FactoryBot.create(:robot) }
let!(:robot4) { FactoryBot.create(:robot, :with_shipment) }
background { visit root_path }
scenario 'send shipment' do
require 'rails_helper'
RSpec.describe Robot, 'Instance Methods', type: :model do
context 'when rusty' do
it 'should be recycled' do
robot = FactoryBot.create(:robot, :rusty)
expect(robot.should_be_recycled?).to eq true
end
end
class Robot < ApplicationRecord
validates :name, presence: true
validates :color, presence: true
belongs_to :color
belongs_to :shipment, optional: true
has_and_belongs_to_many :statuses
def should_be_recycled?
@somethvictory
somethvictory / example_1_robot_spec.rb
Last active July 17, 2018 14:51
Group similar specs in the same describe block.
require 'rails_helper'
RSpec.describe Robot, 'Validations', type: :model do
it { is_expected.to validate_presence_of(:name) }
it { is_expected.to validate_presence_of(:color) }
end
RSpec.describe Robot, 'Associations', type: :model do
it { is_expected.to belong_to(:color) }
it { is_expected.to have_and_belong_to_many(:statuses) }
@somethvictory
somethvictory / server_connection.rb
Created June 12, 2018 14:22
Sample singleton in Ruby
class ServerConnection
include Singleton
def connection
@connection ||= Server.new(
key: ENV['ACCESS_KEY'],
host: ENV['HOST'],
username: ENV['USERNAME']
)
end
@somethvictory
somethvictory / response.json
Last active June 13, 2018 13:57
A sample response from domain searching api
{
"response": {
"status": {
"code": 200,
"message": "OK"
},
"body": {
"type": "domain",
"name": "some-domain.com",
"price": "11.00",
@somethvictory
somethvictory / domain.rb
Created June 12, 2018 13:41
Data Transfer Object example in Ruby
class DTO::Domain
attr_reader :type, :name, :price, :status
def initialize(data)
@type = data['body']['type']
@name = data['body']['name']
@price = data['body']['price']
@status = data['body']['status']
end