mirror of
https://github.com/aasm/aasm
synced 2023-03-27 23:22:41 -04:00
add specs
This commit is contained in:
parent
8622d3e7b8
commit
baddd138ba
3 changed files with 37 additions and 11 deletions
|
@ -5,17 +5,10 @@ ActiveRecord::Migration.suppress_messages do
|
|||
end
|
||||
end
|
||||
|
||||
ActiveRecord::Migration.create_table "simple_new_dsls", :force => true do |t|
|
||||
t.string "status"
|
||||
end
|
||||
ActiveRecord::Migration.create_table "multiple_simple_new_dsls", :force => true do |t|
|
||||
t.string "status"
|
||||
end
|
||||
ActiveRecord::Migration.create_table "implemented_abstract_class_dsls", :force => true do |t|
|
||||
t.string "status"
|
||||
end
|
||||
ActiveRecord::Migration.create_table "users", :force => true do |t|
|
||||
t.string "status"
|
||||
%w(simple_new_dsls multiple_simple_new_dsls implemented_abstract_class_dsls users multiple_namespaceds).each do |table_name|
|
||||
ActiveRecord::Migration.create_table table_name, :force => true do |t|
|
||||
t.string "status"
|
||||
end
|
||||
end
|
||||
|
||||
ActiveRecord::Migration.create_table "complex_active_record_examples", :force => true do |t|
|
||||
|
|
16
spec/models/active_record/namespaced.rb
Normal file
16
spec/models/active_record/namespaced.rb
Normal file
|
@ -0,0 +1,16 @@
|
|||
class MultipleNamespaced < ActiveRecord::Base
|
||||
include AASM
|
||||
|
||||
aasm(:status, namespace: :car) do
|
||||
state :unsold, initial: true
|
||||
state :sold
|
||||
|
||||
event :sell do
|
||||
transitions from: :unsold, to: :sold
|
||||
end
|
||||
|
||||
event :return do
|
||||
transitions from: :sold, to: :unsold
|
||||
end
|
||||
end
|
||||
end
|
|
@ -331,6 +331,23 @@ if defined?(ActiveRecord)
|
|||
expect(MultipleSimpleNewDsl.unknown_scope).to contain_exactly(dsl2)
|
||||
end
|
||||
end
|
||||
|
||||
context "when namespeced" do
|
||||
it "add namespaced scopes" do
|
||||
expect(MultipleNamespaced).to respond_to(:car_unsold)
|
||||
expect(MultipleNamespaced).to respond_to(:car_sold)
|
||||
|
||||
expect(MultipleNamespaced.car_unsold.is_a?(ActiveRecord::Relation)).to be_truthy
|
||||
expect(MultipleNamespaced.car_sold.is_a?(ActiveRecord::Relation)).to be_truthy
|
||||
end
|
||||
it "add unnamespaced scopes" do
|
||||
expect(MultipleNamespaced).to respond_to(:unsold)
|
||||
expect(MultipleNamespaced).to respond_to(:sold)
|
||||
|
||||
expect(MultipleNamespaced.unsold.is_a?(ActiveRecord::Relation)).to be_truthy
|
||||
expect(MultipleNamespaced.sold.is_a?(ActiveRecord::Relation)).to be_truthy
|
||||
end
|
||||
end
|
||||
end # scopes
|
||||
|
||||
describe "direct assignment" do
|
||||
|
|
Loading…
Reference in a new issue