Last active
February 13, 2018 21:44
-
-
Save bhserna/925cba5b8b0448a08b6c035c0d9f386f to your computer and use it in GitHub Desktop.
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 CompaniesController < ApplicationController | |
STORE = Company | |
def new | |
form = CRM.new_company_form | |
render locals: { form: form } | |
end | |
def create | |
status = CRM.create_company(params[:company], STORE) | |
if status.success? | |
redirect_to admin_companies_path, notice: "La empresa ha sido creado exitosamente." | |
else | |
render :new, locals: { form: status.form } | |
end | |
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
require_relative "spec_helper" | |
module CRM | |
RSpec.describe "Create company" do | |
def new_company_form | |
CRM.new_company_form | |
end | |
def create_company(params, store) | |
CRM.create_company(params, store) | |
end | |
attr_reader :store, :params, :logo | |
before do | |
@store = DummyStore | |
@params = { "name" => "D1", "logo" => @logo = Object.new } | |
end | |
it "has a form" do | |
form = new_company_form | |
expect(form.name).to eq nil | |
expect(form.logo).to eq nil | |
end | |
describe "creates a record adding the slug" do | |
example do | |
expect(store).to receive(:create).with(name: "D1", logo: logo, slug: "d1") | |
create_company(params, store) | |
end | |
example do | |
name = "uno Dos trEs" | |
slug = "uno-dos-tres" | |
expect(store).to receive(:create).with(name: name, logo: logo, slug: slug) | |
create_company(params.merge("name" => name), store) | |
end | |
end | |
it "returns success" do | |
status = create_company(params, store) | |
expect(status).to be_success | |
end | |
describe "without name" do | |
it "does not returns success" do | |
status = create_company({}, store) | |
expect(status).not_to be_success | |
end | |
it "does not creates the record" do | |
expect(store).not_to receive(:create) | |
create_company({}, store) | |
end | |
it "returns a blank error" do | |
status = create_company({}, store) | |
expect(status.form.errors[:name]).to eq ["no puede estar en blanco"] | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment