This file contains hidden or 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 buy(buyer) | |
| if self.user != buyer | |
| self.date_sale = Time.now | |
| self.buyer = buyer | |
| else | |
| # Invalid | |
| end | |
| end |
This file contains hidden or 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
| resources :users do | |
| get :confirm_email | |
| end | |
| ##### | |
| user_confirm_email GET /users/:user_id/confirm_email(.:format) {:action=>"confirm_email", :controller=>"users"} | |
| ##### |
This file contains hidden or 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 'spec_helper' | |
| describe UsersController do | |
| describe "confirm email" do | |
| before(:each) do | |
| @confirmed_user = Factory.create(:confirmed_user) | |
| @confirmed_user.email = "new"+@confirmed_user.email | |
| @confirmed_user.save |
This file contains hidden or 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 Offer < ActiveRecord::Base | |
| belongs_to :user | |
| attr_readonly :user | |
| attr_accessible :user,:title,:description,:price | |
| validates :user, :presence => true | |
| validates :title, :presence => true | |
| validates :description, :presence => true | |
| validates :price, :presence => true |
This file contains hidden or 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 CreateOffers < ActiveRecord::Migration | |
| def self.up | |
| create_table :offers do |t| | |
| t.string :title | |
| t.string :description | |
| t.integer :seller_id ## The user_id from the seller | |
| t.integer :buyer_id ## The user_id from the buyer | |
| t.timestamps | |
| end | |
| end |
This file contains hidden or 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
| context "correct format" do | |
| it "should be invalid with an invalid email address" do | |
| invalid_email_addresses.each do |invalid| | |
| @user.email = invalid | |
| @user.should_not be_valid | |
| end | |
| end | |
| it "should be valid with an valid email address" do |
This file contains hidden or 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 User < ActiveRecord::Base | |
| belongs_to :address | |
| accepts_nested_attributes_for :address | |
| # Include default devise modules. Others available are: | |
| # :token_authenticatable, :confirmable, :lockable and :timeoutable | |
| devise :database_authenticatable, :registerable, | |
| :recoverable, :rememberable, :trackable, :confirmable, :lockable, :validatable | |
| # Setup accessible (or protected) attributes for your model |
This file contains hidden or 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
| user = Factory.build(:user) | |
| user.should_receive(:save).and_return(true) | |
| User.stub(:new).and_return(user) |
This file contains hidden or 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
| # Controller | |
| def create | |
| @user = User.new(params[:user]) | |
| respond_to do |format| | |
| if @user.save | |
| format.html { redirect_to(@user, :notice => 'instructions for confirming') } | |
| else | |
| format.html { redirect_to(@user, :notice => 'Error') } | |
| end |
This file contains hidden or 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
| user = Factory.create(:user) | |
| user.stub(:valid?).and_return(false) | |
| post :create, :user => user |