Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduces instance level skip validation option. #644

Merged

Conversation

Nitin-Salunke
Copy link
Contributor

We had a specific requirement to skip validations for transitions at the instance level at a few places but at the same time, we wanted the transitions for the model to validated at other places.

The change in this PR just adds a method like

some_event_name_without_validation! which actually skips the validation and set the object state according to the transitions defined.

@Nitin-Salunke Nitin-Salunke force-pushed the instance_level_skip_validation branch from d1b1628 to bcf9183 Compare July 30, 2019 15:18
@Nitin-Salunke
Copy link
Contributor Author

@anilmaurya please have a look at this PR, check if this functionality can be merged.

README.md Outdated
@@ -739,6 +739,13 @@ class Job < ActiveRecord::Base
end
```

Also You can skip the validation at instance level with `some_event_name_without_validation!` method.
With this you have the flexibility of having validation for all your transitions by default and then skip it wherever required.
Please not that only update column will be updated as mentioned in the above example.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Please not that only update column will be updated as mentioned in the above example.
Please note that only state column will be updated as mentioned in the above example.

expect(example.state).to eq('complete')
end

it 'shouldn\'t affect the behaviour of existing method after calling _without_validation method' do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
it 'shouldn\'t affect the behaviour of existing method after calling _without_validation method' do
it 'shouldn't affect the behaviour of existing method after calling _without_validation! method' do

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@anilmaurya backslash was intentional to escape the single quote.

README.md Outdated
With this you have the flexibility of having validation for all your transitions by default and then skip it wherever required.
Please not that only update column will be updated as mentioned in the above example.
<br/>
<br/>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<br/>

README.md Outdated
With this you have the flexibility of having validation for all your transitions by default and then skip it wherever required.
Please not that only update column will be updated as mentioned in the above example.
<br/>
<br/>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<br/>

@anilmaurya
Copy link
Member

Hi @Nitin-Salunke ,

Thank you for your contribution and patience.
Your changes looks good to me, I have suggested some minor changes.

@Nitin-Salunke Nitin-Salunke force-pushed the instance_level_skip_validation branch from bcf9183 to a024ba8 Compare August 14, 2019 08:35
@Nitin-Salunke
Copy link
Contributor Author

@anilmaurya I have done the changes suggested by you, please have a look.

@Nitin-Salunke Nitin-Salunke force-pushed the instance_level_skip_validation branch 3 times, most recently from ad95c86 to 0404e3e Compare August 14, 2019 09:31
@anilmaurya
Copy link
Member

@Nitin-Salunke PR looks good but travis build is failing for some reason.
Can you help in resolving travis build problem ?

@Nitin-Salunke
Copy link
Contributor Author

@Nitin-Salunke PR looks good but travis build is failing for some reason.
Can you help in resolving travis build problem ?

No brainer one is failing with the connection refused error.

@Nitin-Salunke
Copy link
Contributor Author

@Nitin-Salunke PR looks good but travis build is failing for some reason.
Can you help in resolving travis build problem ?

@anilmaurya yes sure.

@Nitin-Salunke Nitin-Salunke force-pushed the instance_level_skip_validation branch 4 times, most recently from 6d5b0d7 to d5dcedb Compare August 14, 2019 12:25
@Nitin-Salunke Nitin-Salunke force-pushed the instance_level_skip_validation branch from d5dcedb to 305c2be Compare September 2, 2019 19:26
@codeclimate
Copy link

codeclimate bot commented Sep 2, 2019

Code Climate has analyzed commit 305c2be and detected 0 issues on this pull request.

View more on Code Climate.

@Nitin-Salunke
Copy link
Contributor Author

@anilmaurya please merge the PR.

@codecov-io
Copy link

codecov-io commented Sep 2, 2019

Codecov Report

Merging #644 into master will increase coverage by 0.03%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #644      +/-   ##
==========================================
+ Coverage   95.14%   95.17%   +0.03%     
==========================================
  Files          35       35              
  Lines        1214     1223       +9     
==========================================
+ Hits         1155     1164       +9     
  Misses         59       59
Impacted Files Coverage Δ
lib/aasm/base.rb 96.87% <100%> (+0.23%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0ce55f2...305c2be. Read the comment docs.

@anilmaurya anilmaurya merged commit aa34baf into aasm:master Sep 3, 2019
@anilmaurya
Copy link
Member

@Nitin-Salunke Thank you for your contribution. ⚡️

@anilmaurya
Copy link
Member

Released 5.0.6 version with this feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants