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
# Stock allocator | |
This article explains the concept of a stock allocator and its usage. | |
During the checkout process, after the delivery step, the order stocks the ordered stock items | |
to ship them. | |
The stock allocator defines the logic with which these packages are created. | |
The allocator is called by `Spree::Stock::SimpleCoordinator` when allocating inventory for an order. |
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
#include<stdio.h> | |
int main() { | |
int numbers[2]; | |
printf("Inserisci il primo numero: "); | |
scanf("%d", &numbers[0]); | |
printf("Inserisci il secondo numero: "); | |
scanf("%d", &numbers[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
class House | |
has_many :photos | |
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
RSpec.describe Photo | |
let(:house) { House.create! } | |
subject { described_class.new(house: house) } | |
it 'is marked as cover when saved' do | |
expect { | |
subject.save! | |
subject.reload | |
}.to change(subject, :cover).to(true) | |
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
class Review < ActiveRecord::Base | |
belongs_to :book | |
trigger.after(:insert) do | |
<<-SQL | |
UPDATE books SET reviews_count = reviews_count + 1 WHERE id = NEW.book_id; | |
SQL | |
end | |
trigger.after(:update).of(:book_id) do |
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
RSpec.describe Review do | |
let(:book) { Book.create! } | |
subject { Review.new(book: book) } | |
it "increments the book's reviews_count when saving" do | |
expect { | |
subject.save! | |
}.to change(book, :reviews_count).by(1) | |
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
class BooksController < ApplicationController | |
def top_ten | |
@books = Book.order('reviews_count DESC').limit(10) | |
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
class Book < ActiveRecord::Base | |
has_many :reviews | |
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
<?php | |
$period = isset($_POST['period']) ? trim($_POST['period']) : ''; | |
echo <<<EOF | |
<form method="post" action="{$_SERVER['REQUEST_URI']}"> | |
<div> | |
<label for="period">Periodo:</label> | |
<input type="text" name="period" id="period" value="{$period}"> | |
</div> |
NewerOlder