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
# POST | |
def check_assignation | |
@inventory_ids = params[:inv] | |
@inventories = OleCore::Inventory.includes(:course, account: {subscription: :subscription_plan}) | |
.where(id: params[:inv]) | |
prevent_empty_trainees_and_courses | |
# If this assignation doesn't require addons, no confirmation required either. | |
if !CourseAssigner.requires_addons?(@inventories, @checked_users, current_user) |
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
Spree::LineItem.class_eval do | |
def offering | |
variant.offering(self.qty) | |
end | |
end | |
Spree::Variant.class_eval do | |
# has_many :volume_prices (viene de la gema) | |
has_many :offerings |
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
Failures: | |
1) Spree::Admin::VariantsController POST Create a new variant with associated course | |
Failure/Error: Spree::Variant.all.count.should eq(2) | |
expected: 2 | |
got: 1 | |
(compared using ==) | |
# ./spec/controllers/spree/admin/variants_controller_spec.rb:26:in `block (3 levels) in <top (required)>' |
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 Search | |
def initialize(searchable) | |
@searchable = searchable | |
end | |
def starts_with(letter, attribute) | |
@searchable.where(attribute=> 'letter') # would be some variant of a LIKE query. | |
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 ContentProviderCalculator | |
def calculate(commissionable) | |
olei = # find olei content provider | |
olec = # find olec content provider | |
content_amount = commissionable.subtotal * .2 # 20% goes to content providers | |
if commissionable.premium? | |
# create commission for olei of 66.7% of content_amount | |
# create commission for olec of 33.3% of content_amount | |
else |
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
def update | |
# fetch @conversation having its rank updated. | |
# | |
conversations = @discussion.conversations.order(:rank).to_a | |
# Move conversation to new position by inserting in array at rank and deleting it from previous position. | |
conversations.insert(@conversation.rank, conversations.delete_at(@conversation)) | |
# Update all conversation ranks to correspond to new array order. | |
# Very inefficient as this uses a n+1 query. You could optimize to use update_all |
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 ResultSetsController < ApplicationController | |
def index | |
@survey = Survey.find(params[:id]) # should be :survey_id if you want to conform to rails standard. | |
@quiz = @survey.quiz # try to retrieve quiz from survey, you should not have to load all the result sets to find the right quiz id. | |
@result_sets = Survey.result_sets.owned_by(result_set_owner) | |
# Rest of code follows below but requires major refactoring. | |
end | |
private | |
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 Programme < AR::Base | |
has_many :villages | |
has_many :conversations, though: :villages | |
end | |
class Village < AR::Base | |
has_many :discussions | |
has_many :conversations, through: :discussions | |
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 Change < ActiveRecord::Base | |
has_many :conversations | |
validates :name, presence: true | |
def self.top_ranked(load_conversation=true) | |
with_rank(load_conversation).order("conversations_rank desc").limit(1) | |
end | |
def self.with_rank(load_conversation=true) |
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 Village < AR::Base | |
has_many :discussions | |
has_many :conversations, through: :discussions | |
has_many :changes, through: :conversations | |
def top_change | |
changes.merge Change.top_ranked(false) | |
end | |
end |