Created
May 24, 2013 20:39
-
-
Save dmgarland/5646372 to your computer and use it in GitHub Desktop.
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 Project do | |
| describe 'nested attributes' do | |
| before do | |
| json = { | |
| "title" => "My Amazing Project", | |
| "skills_attributes" => [ | |
| { "name" => "Ruby" }, | |
| { "name" => "AJAX" }, | |
| { "name" => "Backbone" } | |
| ] | |
| } | |
| @project = Project.new(json) | |
| end | |
| it "should have filled in all the skills" do | |
| @project.skills.length.should eq(3) | |
| @project.skills.first.name.should eq("Ruby") | |
| end | |
| it "should give me a hash with as_json" do | |
| @project.as_json.class.should eq(Hash) | |
| end | |
| it "should give me a string with to_json" do | |
| @project.to_json.class.should eq(String) | |
| end | |
| 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
| require 'spec_helper' | |
| describe ProjectsController do | |
| before do | |
| @user = User.make! | |
| end | |
| describe 'POST to create' do | |
| before do | |
| json = Project.make(:user => @user).as_json.merge({ | |
| :skills_attributes => ([Skill.make] * 3).as_json | |
| }) | |
| json.delete :skills | |
| post :create, :project => json, :user_id => @user.id | |
| end | |
| it "should work" do | |
| expect(response).to be_success | |
| end | |
| it "should create a project and some skills" do | |
| expect(Project.count).to eq(1) | |
| expect(Skill.count).to eq(3) | |
| end | |
| it "should assign the skills to its proejct" do | |
| assigns(:project).skills.length.should eq(3) | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment