Skip to content

Instantly share code, notes, and snippets.

View msarit's full-sized avatar
☀️
Ready for Spring!

Arit Developer msarit

☀️
Ready for Spring!
View GitHub Profile
@msarit
msarit / linkedlistnode1and2.rb
Created April 5, 2018 14:27
Linked List Node Exercises 1 & 2
class LinkedListNode
attr_accessor :value, :next_node
def initialize(value, next_node=nil)
@value = value
@next_node = next_node
end
end
class Stack
@msarit
msarit / grams_edit_action.rb
Last active April 6, 2018 15:04
grams#edit action
describe "grams#edit action" do
it "shouldn't let a user who did not create the gram edit a gram" do
gram = FactoryBot.create(:gram)
user = FactoryBot.create(:user)
sign_in user
get :edit, params: { id: gram.id }
expect(response).to have_http_status(:forbidden)
end
end
@msarit
msarit / factories.rb
Created April 6, 2018 15:09
factories
FactoryBot.define do
factory :gram do
sequence :message do |m|
"Hello! This is dummy message No. #{m}."
end
association :user
end
end
describe "grams#edit action" do
it "shouldn't let a user who did not create the gram edit a gram" do
gram = FactoryBot.create(:gram)
diff_user = FactoryBot.create(:user)
sign_in diff_user
get :edit, params: { id: gram.id }
expect(response).to have_http_status(:forbidden)
end
end
describe "grams#destroy action" do
it "should return a 404 error if gram with the specified id cannot be found" do
user = FactoryBot.create(:user)
sign_in user
delete :destroy, params: { id: 'GHOST' }
expect(response).to have_http_status(:not_found)
end
end
class GramsController < ApplicationController
before_action :authenticate_user!, only: [:new, :create, :edit, :update, :destroy]
class LinkedListNode
attr_accessor :value, :next_node
def initialize(value, next_node=nil)
@value = value
@next_node = next_node
end
end
class Stack
require_relative "./linkedlistnode1and2.rb"
RSpec.describe 'mutate_list' do
it "should return the expected values" do
node1 = LinkedListNode.new(1)
node2 = LinkedListNode.new(2,node1)
mutate = mutate_list(node2)
expect(mutate.value).to eq 1
expect(mutate.next_node.value).to eq 2
expect(mutate.next_node.next_node).to eq nil
require_relative "./linkedlistnode1and2.rb"
RSpec.describe 'mutate_list' do
it "should return the expected values" do
node1 = LinkedListNode.new(1)
node2 = LinkedListNode.new(2,node1)
rev = reverse_list(node2)
mutate = mutate_list(node2)
expect(rev).to eq mutate
end
module Luhn
def self.is_valid?(number)
array = number.to_s.chars.map(&:to_i)
array2 = []
array.reverse.each_with_index do |digit,digit_index|
if digit_index % 2 == 1
digit = digit * 2
if digit >= 10