Skip to content
gropax edited this page Apr 29, 2015 · 1 revision

LexicalEntry

# Class Methods
# CRUD Methods (nothing special)
LexicalEntry.new
LexicalEntry.create
LexicalEntry.where

# Instance Methods
# Fields

# #language
lexical_entry = LexicalEntry.create(language: 'cmn', ...)
lexical_entry.language #=> 'cmn'
lexical_entry.language = 'fra' #=> LexicalEntryError: Can't update language

lexical_entry = LexicalEntry.new(language: nil, ...)
lexical_entry.valid? #=> false
lexical_entry.errors #=> {language: ["is required"]}


# Associations
# #lemma

# Create a with :lemma key (?: or :lemma_attributes)
lexical_entry = LexicalEntry.create(lemma: lemma_attributes, ...)
lexical_entry.lemma #=> #<Lemma: ...>

# Update with :lemma_attributes key
lexical_entry.update_attributes(lemma_attributes: lemma_attributes)

# lemma= should take a Lemma or a Hash
expect { lexical_entry.lemma = form_not_a_lemma }.to raise(LexicalEntryError)
lexical_entry.lemma

# Not valid without lemma
lexical_entry.lemma = nil
expect(lexical_entry).not_to be_valid
expect(lexical_entry.errors[:lemma]).to eq "is required"

# Not valid with invalid lemma
lexical_entry.lemma = invalid_lemma
expect(lexical_entry).not_to be_valid
expect(lexical_entry.errors[:lemma]).to eq "is not valid"

# Successfuly update lemma attributes
lexical_entry.lemma.some_attr = "some value"
lexical_entry.save
expect(lexical_entry.lemma.some_attr).to eq "some value"
Clone this wiki locally