repo_name stringlengths 6 97 | path stringlengths 3 341 | text stringlengths 8 1.02M |
|---|---|---|
matthijsgroen/game-of-geese | tasks/cucumber.rake | begin
require 'cucumber/rake/task'
namespace :cucumber do
Cucumber::Rake::Task.new(:ok, 'Run features that should pass') do |t|
t.fork = false # You may get faster startup if you set this to false
t.profile = 'default'
end
Cucumber::Rake::Task.new(:wip, 'Run features that are being worked ... |
matthijsgroen/game-of-geese | features/step_definitions/play_steps.rb | Stel(/^ik heb de volgende spelers met de klok mee:$/) do |table|
# table is a Cucumber::Ast::Table
# Table structure:
# | naam | leeftijd | kleur pion |
# | Jan | 12 | zwart |
table.map_headers!(
'naam' => :name,
'leeftijd' => :age,
'kleur pion' => :color
)
table.map_colu... |
matthijsgroen/game-of-geese | lib/gosu-formatter/renderers/die_renderer.rb | <filename>lib/gosu-formatter/renderers/die_renderer.rb<gh_stars>0
#:nodoc:
class DieRenderer
def initialize(window)
@die = { value: 1, x: 0, y: 0 }
@rolling = false
@value = 1
@counter = 0
initialize_die_images(window)
end
def update_game(game)
return unless game
@rolling = game[:die]... |
matthijsgroen/game-of-geese | spec/models/person_spec.rb | <reponame>matthijsgroen/game-of-geese<filename>spec/models/person_spec.rb
require 'spec_helper'
describe Person do
describe 'attributes' do
it 'has a name' do
p = Person.new name: 'Henk'
expect(p.name).to eql 'Henk'
end
it 'has an age' do
p = Person.new age: 34
expect(p.age).to e... |
matthijsgroen/game-of-geese | app/models/rules/curvet.rb | require_relative './base'
module Rules
# When a player lands on this space,
# he can move one space before the first pawn on the board
class Curvet < Base
def enter_space(pawn)
in_scope_of_player do
sorted_pawns = game.pawns.sort { |a, b| b.location <=> a.location }
target_pawn = sorted... |
matthijsgroen/game-of-geese | features/support/transformations/location_transformer.rb | @space = /(?:op |)het \d+(?:de|ste) vakje|daar/
Transform(/(?:op |)het (\d+)(?:de|ste) vakje/) do |location|
@current_location = location.to_i
end
Transform(/daar/) do |_arg|
@current_location
end
|
matthijsgroen/game-of-geese | app/models/rules/base.rb | module Rules
# Base class with
# basic functionality
# every rule can reuse
class Base
def apply_to(player)
applied_rule = dup
applied_rule.player = player
applied_rule
end
def enter_space(_pawn)
end
def leave_space(pawn, die_value)
pawn.location += die_value
en... |
matthijsgroen/game-of-geese | spec/models/game_spec.rb | require 'spec_helper'
require_relative './roles/player'
require_relative './roles/board_pawn'
describe Game do
let(:game) { Game.new }
before do
game.board = double('board', space_count: 50)
end
describe '#join' do
let(:person) { double('person') }
let(:pawn) { double('pawn') }
let(:join) { ... |
matthijsgroen/game-of-geese | spec/spec_helper.rb | root = File.dirname(__FILE__) + '/../app/'
Dir["#{root}/**/*.rb"].each do |file|
load file
end
|
matthijsgroen/game-of-geese | lib/gosu-formatter/renderers/pawn_renderer.rb | #:nodoc:
class PawnRenderer
def initialize(window)
@pawns = {}
initialize_pawn_images(window)
end
def update_game(game)
pawns = game[:players].map { |p| p[:pawn] }
if @pawns.size != pawns.size
reset_pawns(pawns)
else
update_pawns(pawns)
end
end
def transition
@pawns.e... |
matthijsgroen/game-of-geese | spec/models/rules/goose_space_spec.rb | require 'spec_helper'
describe Rules::GooseSpace do
let(:game) { Game.new }
let(:board) { Board.new 40 }
let(:die) { FixedDie.new 5 }
let(:pawn) { Pawn.new color: :blue }
let(:person) { Person.new age: 8 }
before do
game.board = board
game.die = die
game.join person, pawn
end
it 'doubl... |
matthijsgroen/game-of-geese | spec/models/roles/player.rb | <reponame>matthijsgroen/game-of-geese<gh_stars>0
shared_examples_for 'a player' do
it 'has a pawn to play' do
expect(player.pawn).to eql pawn
end
describe '#play_turn' do
let(:pawn) { double('pawn').extend(BoardPawn) }
let(:die) { double('die', roll: nil, value: 6) }
subject { player.play_turn(... |
matthijsgroen/game-of-geese | app/models/person.rb | <reponame>matthijsgroen/game-of-geese
# Person that will play our game
class Person
attr_reader :name, :age
def initialize(attributes)
@name = attributes[:name]
@age = attributes[:age]
end
end
|
matthijsgroen/game-of-geese | app/models/pawn.rb | <reponame>matthijsgroen/game-of-geese
# A physical pawn on the playing field
class Pawn
attr_reader :color
def initialize(attributes)
@color = attributes[:color]
end
end
|
matthijsgroen/game-of-geese | app/models/game.rb | # Our 'concept' of the game, maintaining the rules of the game
class Game
attr_reader :players
attr_accessor :die, :board
attr_reader :winner
def initialize
@players = []
@rules = {}
@players.extend PlayerCircle
end
def join(person, pawn)
player = person.extend Player
player.pawn = paw... |
matthijsgroen/game-of-geese | features/step_definitions/game_rule_steps.rb | Stel(/^(#{space}) is een ganzenvakje$/) do |location|
game.set_rules_for_space(Rules::GooseSpace.new, location)
end
Stel(/^(#{space}) mag je nogmaals dobbelen$/) do |location|
game.set_rules_for_space(Rules::RollAgain.new, location)
end
Stel(/^alleen als je minder dan (\d+) had gegooid$/) do |die_value|
rules =... |
matthijsgroen/game-of-geese | app/models/roles/player.rb | # The role of a person playing game of goose
module Player
attr_accessor :pawn
attr_accessor :game
def place_pawn_on_board
pawn.extend BoardPawn
respecting_rules do
pawn.location = 0
end
end
def play_turn(die)
@die = die
respecting_rules do
move_pawn_using_die
end
fi... |
matthijsgroen/game-of-geese | app/models/rules/roll_again.rb | require_relative './base'
module Rules
# Allows the player to roll again
class RollAgain < Base
attr_accessor :max_die_value
def finish_turn?
return false unless max_die_value
die_value = in_scope_of_player { die.value }
die_value > max_die_value
end
end
end
|
matthijsgroen/game-of-geese | app/models/board.rb | <reponame>matthijsgroen/game-of-geese
# The gameboard with spaces to move pawns across
class Board
attr_reader :space_count
def initialize(space_count)
@space_count = space_count
@labels = {}
end
def set_label_for_space(label, space)
@labels[space] = label
end
def label_for_space(space)
@... |
matthijsgroen/game-of-geese | lib/gosu-formatter/formatter.rb | <reponame>matthijsgroen/game-of-geese
require 'cucumber/formatter/pretty'
require 'drb/drb'
require_relative './listeners/die_listener'
require_relative './listeners/pawn_listener'
module Cucumber
module Formatter
# Creates a layout on screen to show the cucumber steps
# and the active state of the game
... |
matthijsgroen/game-of-geese | app/models/rules/goto_space.rb | require_relative './base'
module Rules
# Brings the player to a new location
class GotoSpace < Base
def initialize(destination)
@destination = destination
end
def enter_space(pawn)
local_destination = destination
in_scope_of_player do
respecting_rules do
pawn.locati... |
matthijsgroen/game-of-geese | lib/gosu-formatter/game_window.rb | require 'gosu'
require_relative 'space_generator'
require_relative './renderers/pawn_renderer'
require_relative './renderers/die_renderer'
require_relative './renderers/board_renderer'
# this is the main game window
class GameWindow < Gosu::Window
attr_accessor :spaces
attr_accessor :update
COLOR_WHITE = Gosu::C... |
matthijsgroen/game-of-geese | spec/models/rules/base_spec.rb | require 'spec_helper'
describe Rules::Base do
describe '#apply_to' do
let(:player) { double('player') }
it 'makes a duplicate with an assigned player' do
inst1 = described_class.new
inst2 = inst1.apply_to(player)
expect(inst1.player).to be_nil
expect(inst2.player).to eql player
... |
matthijsgroen/game-of-geese | spec/models/roles/board_pawn.rb | <filename>spec/models/roles/board_pawn.rb
shared_examples_for 'a board pawn' do
it 'has a location on the board' do
expect(subject.location).to eql 0
end
end
|
matthijsgroen/game-of-geese | app/models/rules/goose_space.rb | <reponame>matthijsgroen/game-of-geese
require_relative './base'
module Rules
# When a player lands on this space,
# he can move the amount of value of the dice again
class GooseSpace < Base
def enter_space(pawn)
in_scope_of_player do
respecting_rules do
pawn.location += die.value
... |
matthijsgroen/game-of-geese | features/step_definitions/board_setup_steps.rb | <filename>features/step_definitions/board_setup_steps.rb
Stel(/^ik heb een speelbord met (\d+) vakjes$/) do |space_count|
@game = Game.new
game.board = Board.new(space_count)
game.die = Die.new
end
Stel(/^alle pionnen staan op het startvakje$/) do
# No assertion at the moment that requires implementation here
... |
matthijsgroen/game-of-geese | spec/models/board_spec.rb | <gh_stars>0
require 'spec_helper'
describe Board do
let(:space_count) { 30 }
let(:board) { Board.new space_count }
describe '#spaces' do
it 'returns the amount of spaces on the board' do
expect(board.space_count).to eql space_count
end
end
describe '#set_label_for_space' do
it 'attaches ... |
matthijsgroen/game-of-geese | lib/gosu-formatter/listeners/die_listener.rb | <filename>lib/gosu-formatter/listeners/die_listener.rb
# tell gosu when die is rolled
module DieListener
attr_accessor :formatter_listener
def roll
super.tap { formatter_listener.roll(value) }
end
end
|
matthijsgroen/game-of-geese | spec/models/rules/curvet_spec.rb | <reponame>matthijsgroen/game-of-geese<gh_stars>0
require 'spec_helper'
describe Rules::Curvet do
let(:game) { Game.new }
let(:board) { Board.new 40 }
let(:die) { FixedDie.new 5 }
let(:pawn) { Pawn.new color: :blue }
let(:person) { Person.new age: 8 }
let(:first_person) { Person.new age: 9 }
let(:first_... |
matthijsgroen/game-of-geese | features/support/env.rb | <gh_stars>0
root = File.dirname(__FILE__) + '/../../app/'
[:space, :current_location, :game].each do |reader|
define_method(reader) do
instance_variable_get("@#{reader}")
end
end
Dir["#{root}/**/*.rb"].each do |file|
load file
end
|
matthijsgroen/game-of-geese | features/support/demo_mode.rb | require_relative '../../lib/gosu-formatter/formatter'
AfterStep do
formatter = Cucumber::Formatter::Demo
formatter.update_game(@game) if formatter.active && @game
end
|
matthijsgroen/game-of-geese | app/models/die.rb | # A standard die with 6 faces
class Die
attr_reader :value
def roll
@value = rand(1..6)
end
end
|
matthijsgroen/game-of-geese | features/support/helpers/dutch_helpers.rb | # Helpers to translate dutch names into
# english / ruby
module DutchHelpers
# remap colors to english symbols
def map_dutch_color_to_symbol(dutch_color)
{
'zwart' => :black,
'blauw' => :blue,
'paars' => :purple,
'geel' => :yellow,
'groen' => :green,
'rood' => :red,
'... |
matthijsgroen/game-of-geese | app/models/fixed_die.rb | # A fixed die that always returns a pre-defined value
class FixedDie
attr_reader :value
def initialize(fixed_value)
@value = fixed_value
end
def roll
end
end
|
asimcan/vagrant-boxes | centos-postgres/manifests/modules/iptables/spec/classes/iptables_spec.rb | <filename>centos-postgres/manifests/modules/iptables/spec/classes/iptables_spec.rb
require "#{File.join(File.dirname(__FILE__),'..','spec_helper.rb')}"
describe 'iptables' do
let(:node) { 'iptables1.example42.com' }
let(:facts) { { :operatingsystem => 'ubuntu', :osver_maj => 12 } }
it { should contain_ipta... |
jetthoughts/bundler | spec/install/process_lock_spec.rb | # frozen_string_literal: true
RSpec.describe "process lock spec" do
describe "when an install operation is already holding a process lock" do
before { FileUtils.mkdir_p(default_bundle_path) }
it "will not run a second concurrent bundle install until the lock is released" do
thread = Thread.new do
... |
jetthoughts/bundler | spec/commands/doctor_spec.rb | <reponame>jetthoughts/bundler
# frozen_string_literal: true
require "stringio"
require "bundler/cli"
require "bundler/cli/doctor"
RSpec.describe "bundle doctor" do
before(:each) do
@stdout = StringIO.new
[:error, :warn].each do |method|
allow(Bundler.ui).to receive(method).and_wrap_original do |m, me... |
jetthoughts/bundler | lib/bundler/deprecate.rb | # frozen_string_literal: true
begin
require "rubygems/deprecate"
rescue LoadError
# it's fine if it doesn't exist on the current RubyGems...
nil
end
module Bundler
if defined? Bundler::Deprecate
# nothing to do!
elsif defined? ::Deprecate
Deprecate = ::Deprecate
elsif defined? Gem::Deprecate
D... |
jetthoughts/bundler | lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/vertex.rb | <reponame>jetthoughts/bundler
# frozen_string_literal: true
module Bundler::Molinillo
class DependencyGraph
# A vertex in a {DependencyGraph} that encapsulates a {#name} and a
# {#payload}
class Vertex
# @return [String] the name of the vertex
attr_accessor :name
# @return [Object] the... |
jetthoughts/bundler | spec/runtime/gem_tasks_spec.rb | # frozen_string_literal: true
RSpec.describe "require 'bundler/gem_tasks'" do
before :each do
bundled_app("foo.gemspec").open("w") do |f|
f.write <<-GEMSPEC
Gem::Specification.new do |s|
s.name = "foo"
end
GEMSPEC
end
bundled_app("Rakefile").open("w") do |f|
f.... |
jetthoughts/bundler | spec/install/force_spec.rb | # frozen_string_literal: true
RSpec.describe "bundle install" do
%w[force redownload].each do |flag|
describe_opts = {}
describe_opts[:bundler] = "< 2" if flag == "force"
describe "with --#{flag}", describe_opts do
before :each do
gemfile <<-G
source "file://#{gem_repo1}"
... |
jetthoughts/bundler | spec/bundler/source/git/git_proxy_spec.rb | # frozen_string_literal: true
RSpec.describe Bundler::Source::Git::GitProxy do
let(:uri) { "https://github.com/bundler/bundler.git" }
subject { described_class.new(Pathname("path"), uri, "HEAD") }
context "with configured credentials" do
it "adds username and password to URI" do
Bundler.settings.tempo... |
jetthoughts/bundler | lib/bundler/current_ruby.rb | <gh_stars>1-10
# frozen_string_literal: true
module Bundler
# Returns current version of Ruby
#
# @return [CurrentRuby] Current version of Ruby
def self.current_ruby
@current_ruby ||= CurrentRuby.new
end
class CurrentRuby
KNOWN_MINOR_VERSIONS = %w[
1.8
1.9
2.0
2.1
2.2... |
jetthoughts/bundler | bundler.gemspec | <reponame>jetthoughts/bundler
# coding: utf-8
# frozen_string_literal: true
require File.expand_path("../lib/bundler/version", __FILE__)
require "shellwords"
Gem::Specification.new do |s|
s.name = "bundler"
s.version = Bundler::VERSION
s.license = "MIT"
s.authors = [
"<NAME>", "<NAME>",... |
jetthoughts/bundler | spec/plugins/hook_spec.rb | <gh_stars>1-10
# frozen_string_literal: true
RSpec.describe "hook plugins" do
before do
build_repo2 do
build_plugin "before-install-plugin" do |s|
s.write "plugins.rb", <<-RUBY
Bundler::Plugin::API.hook "before-install-all" do |deps|
puts "gems to be installed \#{deps.map(&:na... |
jetthoughts/bundler | lib/bundler/process_lock.rb | <gh_stars>1-10
# frozen_string_literal: true
module Bundler
class ProcessLock
def self.lock(bundle_path = Bundler.bundle_path)
lock_file_path = File.join(bundle_path, "bundler.lock")
has_lock = false
File.open(lock_file_path, "w") do |f|
f.flock(File::LOCK_EX)
has_lock = true
... |
jetthoughts/bundler | spec/install/failure_spec.rb | <filename>spec/install/failure_spec.rb
# frozen_string_literal: true
RSpec.describe "bundle install" do
context "installing a gem fails" do
it "prints out why that gem was being installed" do
build_repo2 do
build_gem "activesupport", "2.3.2" do |s|
s.extensions << "Rakefile"
s.w... |
jetthoughts/bundler | lib/bundler/cli/list.rb | <reponame>jetthoughts/bundler
# frozen_string_literal: true
module Bundler
class CLI::List
def initialize(options)
@options = options
end
def run
specs = Bundler.load.specs.reject {|s| s.name == "bundler" }.sort_by(&:name)
return specs.each {|s| Bundler.ui.info s.name } if @options["na... |
jetthoughts/bundler | spec/commands/list_spec.rb | <filename>spec/commands/list_spec.rb
# frozen_string_literal: true
RSpec.describe "bundle list", :bundler => "2" do
before do
install_gemfile <<-G
source "file://#{gem_repo1}"
gem "rack"
G
end
context "with name-only option" do
it "prints only the name of the gems in the bundle" do
... |
jetthoughts/bundler | lib/bundler/cli/binstubs.rb | <reponame>jetthoughts/bundler<gh_stars>0
# frozen_string_literal: true
module Bundler
class CLI::Binstubs
attr_reader :options, :gems
def initialize(options, gems)
@options = options
@gems = gems
end
def run
Bundler.definition.validate_runtime!
path_option = options["path"]
... |
lexmag/wizardry | spec/dummy/config/routes.rb | Dummy::Application.routes.draw do
resources :products, except: :destroy, path_names: { new: :make } do
get :commit, on: :collection
has_wizardry
end
end
|
lexmag/wizardry | spec/spec_helper.rb | ENV['RAILS_ENV'] = 'test'
require File.expand_path('../dummy/config/environment.rb', __FILE__)
require 'minitest/autorun'
require 'action_controller/test_case'
class MiniTest::Spec
include ActiveSupport::Testing::SetupAndTeardown
end
class RoutingSpec < Minitest::Spec
include ActionDispatch::Integration::Runner
... |
lexmag/wizardry | lib/wizardry/base.rb | <gh_stars>1-10
module Wizardry
module Base
extend ActiveSupport::Concern
module ClassMethods
def wizardry(*steps)
class_attribute :steps, :steps_regexp, instance_writer: false
self.steps = steps.map{ |s| s.to_s.inquiry }
self.steps_regexp = Regexp.new(steps.join('|'))
... |
lexmag/wizardry | spec/dummy/app/models/product.rb | <reponame>lexmag/wizardry<filename>spec/dummy/app/models/product.rb<gh_stars>1-10
class Product < ActiveRecord::Base
wizardry :initial, :middle, :final
end
|
lexmag/wizardry | spec/wizardry/routes_spec.rb | <reponame>lexmag/wizardry
require 'spec_helper'
describe 'Wizardry Routing' do
it 'must accept wizardry `edit` routes' do
assert_recognizes({ controller: 'products', action: 'edit', id: '1', step: 'initial'}, '/products/1/edit/initial')
assert_recognizes({ controller: 'products', action: 'edit', id: '1', ste... |
lexmag/wizardry | lib/wizardry.rb | <reponame>lexmag/wizardry<filename>lib/wizardry.rb
require 'wizardry/version'
require 'wizardry/base'
require 'wizardry/routes'
module Wizardry
ORDINALS = %w[first second third fourth fifth sixth seventh]
end
|
lexmag/wizardry | spec/wizardry/base_spec.rb | <gh_stars>1-10
require 'spec_helper'
describe Wizardry::Base do
describe 'class methods' do
it 'must support `wizardry` method' do
assert_respond_to Product, :wizardry
end
it 'must have steps array' do
assert_equal Product.steps, %w[initial middle final]
end
it 'must have steps rege... |
lexmag/wizardry | wizardry.gemspec | <gh_stars>1-10
require File.expand_path('../lib/wizardry/version', __FILE__)
Gem::Specification.new do |gem|
gem.authors = ['<NAME>']
gem.email = ['<EMAIL>']
gem.description = gem.summary = "Simple step-by-step wizard for Rails"
gem.homepage = ''
gem.files = `git ls-files`.split... |
lexmag/wizardry | lib/wizardry/routes.rb | <reponame>lexmag/wizardry
class ActionDispatch::Routing::Mapper
def has_wizardry
unless resource_scope?
raise ArgumentError, "can't use has_wizardry outside resource(s) scope"
end
options = @scope[:scope_level_resource].options
if options.has_key?(:only)
only = Array.wrap(options.delete(... |
cpfergus1/rails-sales-taxes-kata-advanced | spec/features/baskets/user_baskets_page_spec.rb | # frozen_string_literal: true
require 'rails_helper'
RSpec.feature 'Baskets Index Page' do
describe 'When I visit my baskets page' do
let(:user) { create(:user, :with_baskets) }
let(:other_user) { create(:user, :with_baskets) }
before do
sign_in(user)
visit baskets_path(user)
end
i... |
cpfergus1/rails-sales-taxes-kata-advanced | spec/models/line_item_spec.rb | <reponame>cpfergus1/rails-sales-taxes-kata-advanced
# frozen_string_literal: true
RSpec.describe LineItem do
describe 'validations' do
it do
should validate_numericality_of(:price).is_greater_than(0)
should validate_numericality_of(:quantity).is_greater_than(-1)
end
end
describe 'relationshi... |
cpfergus1/rails-sales-taxes-kata-advanced | app/models/baskets/receipt.rb | <gh_stars>0
# frozen_string_literal: true
module Baskets
class Receipt
attr_reader :sales_tax, :total, :line_items
def initialize(basket)
@basket = basket
@sales_tax = 0.0
@total = 0.0
@line_items = receipt_line_items
end
def print_sales_tax
"Sales Taxes: #{'%.2f' % @s... |
cpfergus1/rails-sales-taxes-kata-advanced | app/models/taxes.rb | <reponame>cpfergus1/rails-sales-taxes-kata-advanced
# frozen_string_literal: true
class Taxes
def initialize(item)
@item = item
end
def applicable_tax
(standard_tax + import_tax).round(2)
end
def standard_tax
@item.item_category.name == "Others" ? 0.1 : 0
end
def import_tax
@item.descr... |
cpfergus1/rails-sales-taxes-kata-advanced | spec/features/baskets/basket_receipt_spec.rb | # frozen_string_literal: true
RSpec.describe 'Basket Show Page', type: :feature do
describe "when I try to visit another user's basket receipt" do
let(:user) { create(:user) }
let(:other_user) { create(:basket, :with_items).user }
before(:each) { sign_in(user) }
it 'should return me to the main page... |
cpfergus1/rails-sales-taxes-kata-advanced | spec/features/baskets/create_basket_spec.rb | # frozen_string_literal: true
require 'rails_helper'
RSpec.describe 'Basket Creation Page', type: :feature do
let(:user) { create(:user) }
before { sign_in(user) }
describe 'I upload basket 2 list and click create' do
it 'redirects me to the Basket show page with an itemized receipt' do
visit new_bas... |
cpfergus1/rails-sales-taxes-kata-advanced | spec/factories/basket_factory.rb | <gh_stars>0
# frozen_string_literal: true
FactoryBot.define do
factory :basket do
sequence(:name) { |n| "basket #{n}" }
user
trait :with_items do
after(:create) do |basket|
FactoryBot.create_list(:line_item, 4, basket: basket)
end
end
trait :with_static_items do
after(... |
cpfergus1/rails-sales-taxes-kata-advanced | app/controllers/baskets_controller.rb | <gh_stars>0
# frozen_string_literal: true
class BasketsController < ApplicationController
before_action :authenticate_user!
before_action :correct_user, only: [:show, :destroy]
before_action :check_no_file, :check_file_type, only: [:create]
def index
@baskets = current_user.baskets.order(created_at: :desc... |
cpfergus1/rails-sales-taxes-kata-advanced | app/helpers/application_helper.rb | # frozen_string_literal: true
require 'net/http'
module ApplicationHelper
def full_title(page_title = '')
base_title = 'Basket Reader App'
if page_title.empty?
base_title
else
"#{page_title} | #{base_title}"
end
end
end
|
cpfergus1/rails-sales-taxes-kata-advanced | app/models/item_category.rb | # frozen_string_literal: true
class ItemCategory < ApplicationRecord
has_many :line_items, dependent: :destroy
end
|
cpfergus1/rails-sales-taxes-kata-advanced | spec/models/taxes_spec.rb | # frozen_string_literal: true
RSpec.describe Taxes do
let(:taxable_imported_line_item) { create(:line_item, price: 10, quantity: 1, taxable: true, imported: true) }
let(:taxfree_imported_line_item) { create(:line_item, price: 10, quantity: 1, tax_free: true, imported: true) }
let(:taxfree_line_item) { create(:li... |
cpfergus1/rails-sales-taxes-kata-advanced | app/controllers/static_pages_controller.rb | # frozen_string_literal: true
class StaticPagesController < ApplicationController
def welcome
end
end
|
cpfergus1/rails-sales-taxes-kata-advanced | app/models/line_item.rb | <filename>app/models/line_item.rb
# frozen_string_literal: true
class LineItem < ApplicationRecord
before_validation :set_category
belongs_to :basket, optional: true
belongs_to :item_category
validates :quantity, numericality: {
only_integer: true,
greater_than: -1
}
validates :price, numericalit... |
cpfergus1/rails-sales-taxes-kata-advanced | db/migrate/20210812124129_add_item_category_references_to_line_items.rb | <filename>db/migrate/20210812124129_add_item_category_references_to_line_items.rb
class AddItemCategoryReferencesToLineItems < ActiveRecord::Migration[6.1]
def change
remove_column :line_items, :item_category
add_reference :line_items, :item_category, null: false, foreign_key: true
end
end
|
cpfergus1/rails-sales-taxes-kata-advanced | app/services/cat_image_service.rb | # frozen_string_literal: true
class CatImageService
def self.get_image
JSON.parse(request.body)[0]['url']
end
def self.query
params = { size: 'med' }
uri = URI('https://api.thecatapi.com/v1/images/search')
uri.query = URI.encode_www_form(params)
uri
end
def self.header
request = Net... |
cpfergus1/rails-sales-taxes-kata-advanced | db/migrate/20210811191841_create_line_items.rb | class CreateLineItems < ActiveRecord::Migration[6.1]
def change
create_table :line_items do |t|
t.string :description
t.integer :quantity
t.float :price
t.string :item_category
t.references :basket, null: false, foreign_key: true
t.timestamps
end
end
end
|
cpfergus1/rails-sales-taxes-kata-advanced | config/routes.rb | <filename>config/routes.rb
# frozen_string_literal: true
Rails.application.routes.draw do
get 'baskets/index'
devise_for :users
resources :baskets, except: [:update, :edit]
root 'static_pages#welcome'
# For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html
end
|
cpfergus1/rails-sales-taxes-kata-advanced | db/seeds.rb | # frozen_string_literal: true
# This file should contain all the record creation needed to seed the database with its default values.
# The data can then be loaded with the bin/rails db:seed command (or created alongside the database with db:setup).
#
# Examples:
#
# movies = Movie.create([{ name: 'Star Wars' }, { na... |
cpfergus1/rails-sales-taxes-kata-advanced | spec/models/baskets/receipt_spec.rb | # frozen_string_literal: true
RSpec.describe Baskets::Receipt do
let(:basket) { create(:basket, :with_static_items) }
subject(:receipt) { described_class.new(basket) }
describe 'initialize' do
it 'should create a new Receipt object' do
expect(receipt).to be_a(Baskets::Receipt)
end
end
describ... |
cpfergus1/rails-sales-taxes-kata-advanced | app/models/basket.rb | <filename>app/models/basket.rb<gh_stars>0
# frozen_string_literal: true
class Basket < ApplicationRecord
belongs_to :user
has_many :line_items, dependent: :destroy
def add_items(file)
BasketReader.read_basket(file).each do |line_item|
line_items << line_item
end
end
end
|
cpfergus1/rails-sales-taxes-kata-advanced | spec/factories/line_item_factory.rb | # frozen_string_literal: true
FactoryBot.define do
factory :line_item do
transient do
imported { false }
taxable { false }
tax_free { false }
end
description { ['book', 'box of chocolates', 'headache pills', 'bottle of perfume'].sample }
quantity { rand(1..10) }
price { rand(1.... |
cpfergus1/rails-sales-taxes-kata-advanced | spec/helpers/basket_reader_spec.rb | # frozen_string_literal: true
RSpec.describe 'BasketReader' do
describe 'self.line_item' do
it 'builds a LineItem from parsed text' do
item_text = '1 book at 12.49'
item = BasketReader.line_item(item_text)
expect(item.description).to eq('book')
expect(item.quantity).to eq(1)
expect... |
cpfergus1/rails-sales-taxes-kata-advanced | spec/features/static_pages/welcome_spec.rb | <reponame>cpfergus1/rails-sales-taxes-kata-advanced
# frozen_string_literal: true
require 'rails_helper'
RSpec.feature 'Welcome Page' do
describe 'The welcome landing page', :vcr do
describe 'When not logged in' do
it 'Has welcome page and login elements' do
visit root_path
expect(page).to... |
cpfergus1/rails-sales-taxes-kata-advanced | app/helpers/basket_reader.rb | # frozen_string_literal: true
# frozen_string_literal: true
class BasketReader
def self.file_type_not_allowed?(file)
file.content_type != 'text/plain'
end
def self.read_basket(basket)
basket_contents = File.read(basket).split("\n")
parse_items(basket_contents)
end
def self.parse_items(basket_c... |
cpfergus1/rails-sales-taxes-kata-advanced | db/migrate/20210812141827_remove_null_flag_from_line_items.rb | class RemoveNullFlagFromLineItems < ActiveRecord::Migration[6.1]
def change
change_column_null :line_items, :basket_id, true
end
end
|
cpfergus1/rails-sales-taxes-kata-advanced | spec/services/cat_image_service_spec.rb | <gh_stars>0
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe CatImageService do
it 'fetches an image of a cat', :vcr do
expect(CatImageService.get_image).to match(/https:\/\/cdn2.thecatapi.com\/images\/.*/)
end
end
|
Rainiugnas/password_manager | lib/cli.rb | <filename>lib/cli.rb
# frozen_string_literal: true
require 'password_manager'
require 'cli/input'
require 'cli/option'
require 'cli/storage'
# Handle actions related to the cli interface.
module Cli
# Raise a password manager exception with the given message
# @param message [String] Error message
# @raise [Pa... |
Rainiugnas/password_manager | lib/cli/input/site.rb | <filename>lib/cli/input/site.rb
# frozen_string_literal: true
module Cli
module Input
# Model to retrieve site data from the input
class Site < PasswordManager::Site
# Build the site with the data from the input
def initialize
super ask_site_name!, ask_user_name!, Password.new("password: ... |
Rainiugnas/password_manager | spec/lib/password_manager/crypter/base64_spec.rb | # frozen_string_literal: true
RSpec.describe Base64 do
let(:crypter) { PasswordManager::Crypter::Base64.new }
let(:data) { 'data' }
let(:encrypted_data) { crypter.encrypt data }
describe 'interface' do
it 'should implement crypter interface' do
expect(crypter).to be_crypter
end
end
describe... |
Rainiugnas/password_manager | lib/password_manager/converter.rb | # frozen_string_literal: true
module PasswordManager
# Convert data between several format (site array, json, encrypted)
# Use the given crypters to encrypt / decrypt.
#
# Converter is build from formated data,
# parse and store the data and can be re-use to re-format the data
#
# Encrypting apply the ... |
Rainiugnas/password_manager | lib/password_manager/crypter.rb | <filename>lib/password_manager/crypter.rb
# frozen_string_literal: true
require_relative 'crypter/aes'
require_relative 'crypter/base64'
module PasswordManager
# Namespace which contains all crypter classes.
# A crypter have an encrypt and decrypt method use to format data.
module Crypter
end
end
|
Rainiugnas/password_manager | lib/password_manager/crypter/base64.rb | <reponame>Rainiugnas/password_manager<gh_stars>0
# frozen_string_literal: true
module PasswordManager
module Crypter
# Handle Base64 format
class Base64
# @param [String] data Data to encrypt
# @return [String] the Base64 encrypted data
def encrypt(data) ::Base64.encode64 data end
# ... |
Rainiugnas/password_manager | password_manager.gemspec | # frozen_string_literal: true
lib = File.expand_path('lib', __dir__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'password_manager/version'
Gem::Specification.new do |spec|
spec.name = 'password_manager'
spec.version = PasswordManager::VERSION
spec.authors = ['Rainiugna... |
Rainiugnas/password_manager | lib/cli/input/password.rb | <reponame>Rainiugnas/password_manager<gh_stars>0
# frozen_string_literal: true
module Cli
module Input
# Model to retrieve password data from the input
# @attr_reader [String] value The password from input
# @attr_reader [String] error Alway nil
# @attr_reader [Boolean] success Alway true
class P... |
Rainiugnas/password_manager | lib/password_manager/exceptions.rb | # frozen_string_literal: true
module PasswordManager
# Global exception class throw by password manager
class PasswordManagerError < RuntimeError; end
# Throw by crypter when the decrypt fail
class DecryptError < PasswordManagerError; end
# Throw by crypter when the encrypt fail
class EncryptError < Pass... |
Rainiugnas/password_manager | spec/lib/cli_spec.rb | # frozen_string_literal: true
# rubocop:disable Metrics/BlockLength
RSpec.describe Cli do
describe '.interupt!' do
it 'should raise an password manager exception with the given message' do
expect { Cli.interupt! 'message' }.to raise_exception 'message'
end
end
describe '.run' do
let(:site1) {... |
Rainiugnas/password_manager | spec/lib/cli/storage_spec.rb | <reponame>Rainiugnas/password_manager<filename>spec/lib/cli/storage_spec.rb
# frozen_string_literal: true
# rubocop:disable Metrics/BlockLength
RSpec.describe Storage do
let(:path) { '/path' }
let(:readable?) { true }
let(:writable?) { true }
let(:data) { 'data' }
let(:storage) { Storage.new path }
befor... |
Rainiugnas/password_manager | spec/lib/password_manager/crypter/aes_spec.rb | <reponame>Rainiugnas/password_manager
# frozen_string_literal: true
# rubocop:disable Metrics/BlockLength
RSpec.describe Aes do
let(:aes_1) { Aes.new '1' }
let(:aes_2) { Aes.new '2' }
let(:data) { 'data' }
let(:encrypted_data) { aes_1.encrypt data }
describe 'interface' do
it 'should implement crypter ... |
Rainiugnas/password_manager | lib/cli_file_crypter.rb | # frozen_string_literal: true
require 'cli'
# Handle actions related to the cli file crypter interface.
module CliFileCrypter
# Starter point of the cli file crypter.
# Run CliFileCrypter.run, it use the ARGV arguments to find and execute an action.
# Catch all PasswordManager::PasswordManagerError to stop the ... |
Rainiugnas/password_manager | spec/lib/cli/option_spec.rb | <reponame>Rainiugnas/password_manager
# frozen_string_literal: true
# rubocop:disable Metrics/BlockLength
RSpec.describe Option do
shared_examples :set_option do |argv_options, option_name, expected_value|
context "with #{argv_options.join(' ')}" do
let(:argv) { argv_options }
it "should set the op... |
Rainiugnas/password_manager | lib/cli/input.rb | # frozen_string_literal: true
require_relative 'input/password'
require_relative 'input/password_confirmation'
require_relative 'input/site'
require_relative 'input/stop'
module Cli
# Namespace which contains all input classes.
# Input classe will ask for std_in interaction at initialization.
module Input
end... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.