Merge branch 'bl_tests'
This commit is contained in:
@@ -51,6 +51,8 @@ gem "rails-erd", group: :development
|
||||
|
||||
gem 'travis-lint'
|
||||
|
||||
gem 'faker'
|
||||
gem 'fabrication'
|
||||
|
||||
group :development do
|
||||
gem "binding_of_caller"
|
||||
@@ -64,4 +66,5 @@ end
|
||||
group :test do
|
||||
# Needed for TravisCI
|
||||
gem 'rake'
|
||||
gem "database_cleaner"
|
||||
end
|
||||
|
||||
@@ -73,6 +73,7 @@ GEM
|
||||
coffee-script-source (1.6.3)
|
||||
daemons (1.1.9)
|
||||
dalli (2.6.4)
|
||||
database_cleaner (1.2.0)
|
||||
debug_inspector (0.0.2)
|
||||
devise (3.1.1)
|
||||
bcrypt-ruby (~> 3.0)
|
||||
@@ -89,6 +90,9 @@ GEM
|
||||
erubis (2.7.0)
|
||||
eventmachine (1.0.0)
|
||||
execjs (2.0.2)
|
||||
fabrication (2.9.1)
|
||||
faker (1.2.0)
|
||||
i18n (~> 0.5)
|
||||
foreman (0.63.0)
|
||||
dotenv (>= 0.7)
|
||||
thor (>= 0.13.6)
|
||||
@@ -242,8 +246,11 @@ DEPENDENCIES
|
||||
binding_of_caller
|
||||
coffee-rails
|
||||
dalli
|
||||
database_cleaner
|
||||
devise_browserid_authenticatable
|
||||
dotenv-rails
|
||||
fabrication
|
||||
faker
|
||||
foreman
|
||||
haml-rails
|
||||
has_scope
|
||||
|
||||
@@ -29,4 +29,6 @@ Timeoverflow::Application.configure do
|
||||
|
||||
# Print deprecation notices to the stderr
|
||||
config.active_support.deprecation = :stderr
|
||||
|
||||
config.log_level = :error
|
||||
end
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe InquiriesController do
|
||||
let (:test_organization) { Fabricate(:organization)}
|
||||
let (:member) { Fabricate(:member, organization: test_organization)}
|
||||
let (:another_member) { Fabricate(:member, organization: test_organization)}
|
||||
let! (:inquiry) { Fabricate(:inquiry, user: member.user)}
|
||||
|
||||
describe "GET #index" do
|
||||
context "with a logged user" do
|
||||
it "populates and array of inquiries" do
|
||||
login(another_member.user)
|
||||
|
||||
get 'index'
|
||||
expect(assigns(:inquiries)).to eq([inquiry])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
describe "GET #show" do
|
||||
context "with valid params" do
|
||||
context "with a logged user" do
|
||||
it "assigns the requested inquiry to @inquiry" do
|
||||
login(another_member.user)
|
||||
|
||||
get 'show', id: inquiry.id
|
||||
expect(assigns(:inquiry)).to eq(inquiry)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "POST #create" do
|
||||
context "with valid params" do
|
||||
context "with a logged user" do
|
||||
it "creates a new inquiry" do
|
||||
login(another_member.user)
|
||||
|
||||
expect {
|
||||
post 'create', inquiry: Fabricate.to_params(:inquiry)
|
||||
}.to change(Inquiry,:count).by(1)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "PUT #update" do
|
||||
context "with valid params" do
|
||||
context "with a logged user" do
|
||||
it "located the requested @inquiry" do
|
||||
login(member.user)
|
||||
|
||||
put 'update', id: inquiry.id, inquiry: Fabricate.to_params(:inquiry)
|
||||
expect(assigns(:inquiry)).to eq(inquiry)
|
||||
end
|
||||
|
||||
it "changes @inquiry's attributes" do
|
||||
login(member.user)
|
||||
|
||||
put 'update', id: inquiry.id, inquiry: Fabricate.to_params(:inquiry, user: member, title: "New title", description: "New description")
|
||||
|
||||
inquiry.reload
|
||||
expect(inquiry.title).to eq("New title")
|
||||
expect(inquiry.description).to eq("New description")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "with invalid params" do
|
||||
context "with a logged user" do
|
||||
it "does not change @inquiry's attributes" do
|
||||
login(member.user)
|
||||
|
||||
put :update, id: inquiry.id, inquiry: Fabricate.to_params(:inquiry, user: nil, title: "New title", description: "New description")
|
||||
|
||||
expect(inquiry.title).not_to eq("New title")
|
||||
expect(inquiry.description).not_to eq("New description")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
@@ -0,0 +1,116 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe TransfersController do
|
||||
let (:test_organization) { Fabricate(:organization)}
|
||||
let (:member_admin) { Fabricate(:member, organization: test_organization, manager: true)}
|
||||
let (:member_giver) { Fabricate(:member, organization: test_organization) }
|
||||
let (:member_taker) { Fabricate(:member, organization: test_organization) }
|
||||
|
||||
describe "POST #create" do
|
||||
context "with valid params" do
|
||||
context "with an admin user logged" do
|
||||
subject { post 'create', transfer: {source: member_giver.account.id, destination: member_taker.account.id, amount: 5} }
|
||||
|
||||
it "creates a new Transfer" do
|
||||
login(member_admin.user)
|
||||
|
||||
expect {
|
||||
subject
|
||||
}.to change(Transfer, :count).by 1
|
||||
end
|
||||
|
||||
it "creates two Movements" do
|
||||
login(member_admin.user)
|
||||
|
||||
expect {
|
||||
subject
|
||||
}.to change { Movement.count}.by 2
|
||||
end
|
||||
|
||||
it "updates the balance of both accounts" do
|
||||
login(member_admin.user)
|
||||
|
||||
expect {
|
||||
subject
|
||||
member_giver.reload
|
||||
}.to change { member_giver.account.balance.to_i }.by -5
|
||||
|
||||
expect {
|
||||
subject
|
||||
member_taker.reload
|
||||
}.to change { member_taker.account.balance.to_i }.by 5
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
context "with a regular user logged" do
|
||||
subject { post 'create', transfer: {destination: member_taker.account.id, amount: 5} }
|
||||
|
||||
it "creates a new Transfer" do
|
||||
login(member_giver.user)
|
||||
|
||||
expect {
|
||||
subject
|
||||
}.to change(Transfer, :count).by 1
|
||||
end
|
||||
|
||||
it "creates two Movements" do
|
||||
login(member_giver.user)
|
||||
|
||||
expect {
|
||||
subject
|
||||
}.to change { Movement.count}.by 2
|
||||
end
|
||||
|
||||
it "updates the balance of both accounts" do
|
||||
login(member_giver.user)
|
||||
|
||||
expect {
|
||||
subject
|
||||
member_giver.reload
|
||||
}.to change { member_giver.account.balance.to_i }.by -5
|
||||
|
||||
expect {
|
||||
subject
|
||||
member_taker.reload
|
||||
}.to change { member_taker.account.balance.to_i }.by 5
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# context "with valid params" do
|
||||
# context "with an admin user logged" do
|
||||
# it "creates a new Transfer" do
|
||||
# login(member_admin.user)
|
||||
|
||||
# post 'create', transfer: {source: member_giver.account.id, destination: member_taker.account.id, amount: 5}
|
||||
|
||||
# expect(Transfer.count).to eq(1)
|
||||
# expect(Movement.count).to eq(2)
|
||||
|
||||
# member_giver.reload
|
||||
# member_taker.reload
|
||||
# expect(member_giver.account.balance.to_i).to eq(-5)
|
||||
# expect(member_taker.account.balance.to_i).to eq(5)
|
||||
# end
|
||||
# end
|
||||
|
||||
# context "with a regular user logged" do
|
||||
# it "creates a new Transfer" do
|
||||
# login(member_giver.user)
|
||||
|
||||
# post 'create', transfer: {destination: member_taker.account.id, amount: 5}
|
||||
|
||||
# expect(Transfer.count).to eq(1)
|
||||
# expect(Movement.count).to eq(2)
|
||||
|
||||
# member_giver.reload
|
||||
# member_taker.reload
|
||||
# expect(member_giver.account.balance.to_i).to eq(-5)
|
||||
# expect(member_taker.account.balance.to_i).to eq(5)
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,7 @@
|
||||
Fabricator(:member) do
|
||||
|
||||
user { Fabricate(:user) }
|
||||
organization { Fabricate(:organization) }
|
||||
manager false
|
||||
|
||||
end
|
||||
@@ -0,0 +1,3 @@
|
||||
Fabricator(:organization) do
|
||||
name { Faker::Company.name }
|
||||
end
|
||||
@@ -0,0 +1,36 @@
|
||||
Fabricator(:post) do
|
||||
|
||||
title { Faker::Lorem.sentence }
|
||||
user { Fabricate(:user) }
|
||||
description { Faker::Lorem.paragraph }
|
||||
permanent { false }
|
||||
joinable { false }
|
||||
global { false }
|
||||
|
||||
end
|
||||
|
||||
Fabricator(:inquiry) do
|
||||
|
||||
type "Inquiry"
|
||||
|
||||
title { Faker::Lorem.sentence }
|
||||
user { Fabricate(:user) }
|
||||
description { Faker::Lorem.paragraph }
|
||||
permanent { false }
|
||||
joinable { false }
|
||||
global { false }
|
||||
|
||||
end
|
||||
|
||||
Fabricator(:offer) do
|
||||
|
||||
type "Offer"
|
||||
|
||||
title { Faker::Lorem.sentence }
|
||||
user { Fabricate(:user) }
|
||||
description { Faker::Lorem.paragraph }
|
||||
permanent { false }
|
||||
joinable { false }
|
||||
global { false }
|
||||
|
||||
end
|
||||
@@ -0,0 +1,14 @@
|
||||
Fabricator(:user) do
|
||||
Faker::Config.locale = :es
|
||||
|
||||
username { Faker::Internet.user_name }
|
||||
email { Faker::Internet.email }
|
||||
date_of_birth { DateTime.now.utc }
|
||||
identity_document { sequence(:identity_document, 1) { |n| "X000000#{n}X" } }
|
||||
phone { Faker::PhoneNumber.phone_number }
|
||||
alt_phone { Faker::PhoneNumber.cell_phone }
|
||||
address { Faker::Address.street_address + " " + Faker::Address.zip_code + " " + Faker::Address.city + " (" + Faker::Address.state + ")"}
|
||||
gender { ["male", "female"].shuffle.first }
|
||||
description { Faker::Lorem.paragraph }
|
||||
|
||||
end
|
||||
+22
-1
@@ -27,7 +27,7 @@ RSpec.configure do |config|
|
||||
# If you're not using ActiveRecord, or you'd prefer not to run each of your
|
||||
# examples within a transaction, remove the following line or assign false
|
||||
# instead of true.
|
||||
config.use_transactional_fixtures = true
|
||||
config.use_transactional_fixtures = false
|
||||
|
||||
# If true, the base class of anonymous controllers will be inferred
|
||||
# automatically. This will be the default behavior in future versions of
|
||||
@@ -39,4 +39,25 @@ RSpec.configure do |config|
|
||||
# the seed, which is printed after each run.
|
||||
# --seed 1234
|
||||
config.order = "random"
|
||||
|
||||
config.include ControllerMacros, :type => :controller
|
||||
|
||||
# Database cleaner configuration
|
||||
|
||||
config.before :suite do
|
||||
DatabaseCleaner.strategy = :transaction
|
||||
DatabaseCleaner.clean_with :truncation
|
||||
|
||||
end
|
||||
|
||||
config.before(:each) do
|
||||
DatabaseCleaner.start
|
||||
end
|
||||
|
||||
config.after(:each) do
|
||||
DatabaseCleaner.clean
|
||||
end
|
||||
|
||||
# Controllers must render the content of the view
|
||||
config.render_views
|
||||
end
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
module ControllerMacros
|
||||
|
||||
def login(user = nil)
|
||||
user = Fabricate(:user) unless user
|
||||
|
||||
request.session["user_id"] = user.id
|
||||
request.session["email"] = user.email
|
||||
end
|
||||
|
||||
def current_user
|
||||
@current_user ||= User.find(request.session["user_id"]) if request.session["user_id"]
|
||||
end
|
||||
|
||||
def current_organization
|
||||
@current_organization ||= current_user.try(:organizations).try(:first)
|
||||
end
|
||||
|
||||
end
|
||||
Reference in New Issue
Block a user