statesman 0.8.0 → 0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +17 -0
- data/lib/statesman/machine.rb +2 -0
- data/lib/statesman/version.rb +1 -1
- data/spec/statesman/machine_spec.rb +24 -0
- metadata +2 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 8e2492b67d3e6a95fa6a91b704073a73834f2044
         | 
| 4 | 
            +
              data.tar.gz: 557ecfbe2b21238c38c12ece93296e0faf5f3869
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 052ef370bf131a2772a3f35644872cb13c29c06d7f5153c175853e94c791ab9095ceabf480fb58b8afb056eab69f268f3e0ce4eb6fc48001ceef7821a58191d9
         | 
| 7 | 
            +
              data.tar.gz: d7d13cc58202b83c95a6ec3fba0faf9e6842c959e6b0d43cf21c783af1aca0c8b6a66c3e51e68d684e9c3439d3b0ece04c6c6090b31d29541cb7392461f20f1a
         | 
    
        data/CHANGELOG.md
    CHANGED
    
    
    
        data/README.md
    CHANGED
    
    | @@ -199,6 +199,23 @@ class Order < ActiveRecord::Base | |
| 199 199 | 
             
                       to: :state_machine
         | 
| 200 200 | 
             
            end
         | 
| 201 201 | 
             
            ```
         | 
| 202 | 
            +
            #### Using PostgreSQL JSON column
         | 
| 203 | 
            +
             | 
| 204 | 
            +
            By default, Statesman uses `serialize` to store the metadata in JSON format.
         | 
| 205 | 
            +
            It is also possible to use the PostgreSQL JSON column if you are using Rails 4. To do that
         | 
| 206 | 
            +
             | 
| 207 | 
            +
            * Change `metadata` column type in the transition model migration to `json`
         | 
| 208 | 
            +
             | 
| 209 | 
            +
              ```ruby
         | 
| 210 | 
            +
              # Before
         | 
| 211 | 
            +
              t.text :metadata, default: "{}"
         | 
| 212 | 
            +
              # After
         | 
| 213 | 
            +
              t.json :metadata, default: "{}"
         | 
| 214 | 
            +
              ```
         | 
| 215 | 
            +
             | 
| 216 | 
            +
            * Remove `include Statesman::Adapters::ActiveRecordTransition` statement from your
         | 
| 217 | 
            +
              transition model
         | 
| 218 | 
            +
             | 
| 202 219 |  | 
| 203 220 | 
             
            ## Configuration
         | 
| 204 221 |  | 
    
        data/lib/statesman/machine.rb
    CHANGED
    
    | @@ -66,6 +66,8 @@ module Statesman | |
| 66 66 | 
             
                    from = to_s_or_nil(options[:from])
         | 
| 67 67 | 
             
                    to = Array(options[:to]).map { |item| to_s_or_nil(item) }
         | 
| 68 68 |  | 
| 69 | 
            +
                    raise InvalidStateError, "No to states provided." if to.empty?
         | 
| 70 | 
            +
             | 
| 69 71 | 
             
                    successors[from] ||= []
         | 
| 70 72 |  | 
| 71 73 | 
             
                    ([from] + to).each { |state| validate_state(state) }
         | 
    
        data/lib/statesman/version.rb
    CHANGED
    
    
| @@ -114,6 +114,30 @@ describe Statesman::Machine do | |
| 114 114 | 
             
                  end
         | 
| 115 115 | 
             
                end
         | 
| 116 116 |  | 
| 117 | 
            +
                context "given no 'from' state and a valid 'to' state" do
         | 
| 118 | 
            +
                  it "raises an error" do
         | 
| 119 | 
            +
                    expect do
         | 
| 120 | 
            +
                      machine.transition from: nil, to: :x
         | 
| 121 | 
            +
                    end.to raise_error(Statesman::InvalidStateError)
         | 
| 122 | 
            +
                  end
         | 
| 123 | 
            +
                end
         | 
| 124 | 
            +
             | 
| 125 | 
            +
                context "given a valid 'from' state and a no 'to' state" do
         | 
| 126 | 
            +
                  it "raises an error" do
         | 
| 127 | 
            +
                    expect do
         | 
| 128 | 
            +
                      machine.transition from: :x, to: nil
         | 
| 129 | 
            +
                    end.to raise_error(Statesman::InvalidStateError)
         | 
| 130 | 
            +
                  end
         | 
| 131 | 
            +
                end
         | 
| 132 | 
            +
             | 
| 133 | 
            +
                context "given a valid 'from' state and an empty 'to' state array" do
         | 
| 134 | 
            +
                  it "raises an error" do
         | 
| 135 | 
            +
                    expect do
         | 
| 136 | 
            +
                      machine.transition from: :x, to: []
         | 
| 137 | 
            +
                    end.to raise_error(Statesman::InvalidStateError)
         | 
| 138 | 
            +
                  end
         | 
| 139 | 
            +
                end
         | 
| 140 | 
            +
             | 
| 117 141 | 
             
                context "given an invalid 'from' state" do
         | 
| 118 142 | 
             
                  it "raises an error" do
         | 
| 119 143 | 
             
                    expect do
         | 
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: statesman
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.8. | 
| 4 | 
            +
              version: 0.8.1
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Harry Marr
         | 
| @@ -9,7 +9,7 @@ authors: | |
| 9 9 | 
             
            autorequire: 
         | 
| 10 10 | 
             
            bindir: bin
         | 
| 11 11 | 
             
            cert_chain: []
         | 
| 12 | 
            -
            date: 2014- | 
| 12 | 
            +
            date: 2014-08-19 00:00:00.000000000 Z
         | 
| 13 13 | 
             
            dependencies:
         | 
| 14 14 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 15 15 | 
             
              name: bundler
         |