This file contains hidden or 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
| class LinkedListNode | |
| attr_accessor :value, :next_node | |
| def initialize(value, next_node=nil) | |
| @value = value | |
| @next_node = next_node | |
| end | |
| end | |
| class Stack |
This file contains hidden or 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
| 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 |
This file contains hidden or 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
| FactoryBot.define do | |
| factory :gram do | |
| sequence :message do |m| | |
| "Hello! This is dummy message No. #{m}." | |
| end | |
| association :user | |
| end | |
| end |
This file contains hidden or 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
| 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 |
This file contains hidden or 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
| 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 |
This file contains hidden or 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
| class GramsController < ApplicationController | |
| before_action :authenticate_user!, only: [:new, :create, :edit, :update, :destroy] |
This file contains hidden or 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
| class LinkedListNode | |
| attr_accessor :value, :next_node | |
| def initialize(value, next_node=nil) | |
| @value = value | |
| @next_node = next_node | |
| end | |
| end | |
| class Stack |
This file contains hidden or 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
| 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 |
This file contains hidden or 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
| 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 |
This file contains hidden or 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
| 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 |
OlderNewer