Created
February 14, 2014 17:27
-
-
Save dasibre/9005199 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
| class Manuscript | |
| include Mongoid::Document | |
| embeds_many :authors | |
| field :code, type: String | |
| field :title, type: String | |
| field :status, type: String | |
| field :status_date, type: Date | |
| end | |
| class Author | |
| include Mongoid::Document | |
| embedded_in :manuscript | |
| field :publish_name, type: String | |
| def last_name | |
| publish_name.split(',').first | |
| end | |
| end | |
| #rspec tests | |
| describe 'manuscript status query' do | |
| before :each do | |
| @manuscript = Manuscript.create!(valid_attributes) | |
| @manuscript.authors << Author.new(publish_name: 'Li,John') #would like to mock the Author model | |
| @exitent_author_params = "li" | |
| @nonexitent_author_params = "Witherspoon" | |
| end | |
| describe "#author_match?" do | |
| it "should be true with valid author" do | |
| expect(@manuscript.author_match?(@exitent_author_params)).to eq(true) | |
| end | |
| it "should ignore white space" do | |
| expect(@manuscript.author_match?(" Li")).to eq(true) | |
| end | |
| it "should be false with invalid author" do | |
| expect(@manuscript.author_match?(@nonexitent_author_params)).to eq(false) | |
| end | |
| end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment