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
| WORK: | |
| <%= form_for @user do |f| %> | |
| <div class="field"> | |
| <%= f.label :street %><br /> | |
| <%= f.text_field @user.address.street %> | |
| </div> | |
| <% end %> | |
| DONT Work |
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
| it "should inform the user on failed save" do | |
| user = Factory.create(:user) | |
| user.stub(:valid?).and_return(false) | |
| post :create, :user => user | |
| flash[:notice].should_not be_nil | |
| 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
| def create | |
| @user = User.new(params[:user]) | |
| respond_to do |format| | |
| if @user.save | |
| format.html { redirect_to(@user) } | |
| else | |
| format.html { redirect_to(@user, :notice => 'Error') } |
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 |
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.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
| 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
| 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 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
| 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 |
OlderNewer